Diamonddrake 397 Master Poster

I not really sure what you mean by current word. Infact my answer was based on the title of the thread, I'm not very sure what you want to know.

Diamonddrake 397 Master Poster

the rich text box has a Lines[] property, all you need to know is the line number and you can get the entire lines text via that property array. get that line number however you like, via mouse position or whatever you feel.

Diamonddrake 397 Master Poster

That I can't help you with, I have looked through all the code for the forms library, and I Can't find the definition for the class "Component".

The control class inherits from the component class and passes any subscribers to its paint event to that base class and also gets its graphics object from that class.

Wish I could be more help.

Diamonddrake 397 Master Poster

Thanks sknake, I though I might have to do that, so I already started a simple one just to see what kind of performance I get out if it. And it works great. So I guess I will set off to make a custom control for this.

Just to make a point, making a simple picturebox doesn't concern me, but I created a picturebox control inheriting from picturebox that supports a crop and a uncrop/recrop feature that I put a lot of work into, and now I must relate that to a new control.

Diamonddrake 397 Master Poster

1) When does Form1_Paint(..) called ?
Its called when the form needs to be repainted, see 2

2) When does the Paint event of the form is raised ?
The paint of a control, or form is called when a portion of that object is invalidated or refreshed, which simply means that when windows thinks that part of the screen is no longer accurate, either by passing the WM_PAINT message to the form, or by code on the form itself requesting that it happen.

3) Why the Paint event is raised when I run the application ?
Because the paint event is responsible for drawing the graphics that appear on the control or form, since the application was just opened, its obviously not painted, so It calls Paint()

4) Why the circle is actually drawn on the form ? i.e. what is the relationship between the form class, the "PaintEventArgs e" argument, and the "e.Graphics" object ?

the reason the circle is drawn on the form is because you used the form's paint event. Which means that the PaintEventArgs class that is passed to the handler holds a graphics object that was created for that control (in this case form, forms inherit from control) so when you use the parm, "e" and get its Graphics object, that object is actually the Graphics object of the form, so when you call a drawing method from that object it will always relate to that form.

Diamonddrake 397 Master Poster

you can add commands in the shell using the registry
simply open up the HKEY_CLASSES_ROOT keyset to access all the file types registered with the system, then open that file type, then open its Shell, or ShellEX folder and add a Key, name it whatever you want, Give it the value of a string you want to appear in the shell menu, now give it a child key, call it command, and give it the value of the path you to your application plus any command line args you want to pass to your app, ex, C:\program files\myapp\myapp.exe %1 HKEY_CLASSES_ROOT\Directory\shell\Command\Command where Command = Command Prompt
and
Command\Command = Cmd.exe /k cd %1

Simple, but things get much more complicated if you want an icon, and you can use classids for your app instead of its path, but that's another, much longer story friend. Hope this has helped you.

Diamonddrake 397 Master Poster

that's not the problem at hand, the problem isn't what I changed, The problem is that I can't access parts of the original paint event that I want to modify, because they are sealed.

the code I added works alone, PainCM is a colormatrix variable, (PaintCM == new ColorMatrix()) simply says if the variable hasn't been set to a value, don't use it.

The code I added uses a colormatrix when drawing the image to the control, thus eliminating the need to modify the original image during a preview of the changes.

The problem is, If I override the onPaint event of a picturebox control, I can add to the original paint, or I can remove it, But I cannot modify it, as I dont have access to System.Windows.Forms.ClientUtils.IsCriticalException(exception) (although I could find away around that one I think) but I don't have access to this.pictureBoxState[0x20] nor can I access this.Animate(); , ImageAnimator.UpdateFrames(); , this.imageInstallationType , this.ImageRectangleFromSizeMode() , this.ImageRectangle; the modifications I made in the override are sound, I just can't access those because they are private internal objects of the picturebox, and I tried decompiling and recompiling a changed version of the picturebox control, but it won't build because the protection level of the objects it needs say there are sealed to the windows.Forms lib.

So how can I modify just a few lines of the paint method of the picturebox?

Diamonddrake 397 Master Poster

`````````````````````````````````````````````
Originally Posted by avirag View Post

u can check this link also
http://msdn.microsoft.com/en-us/library/bb383953.aspx

i want to view youtube lively in my appliction using flash player or media player in windows form in c#.net.

lol yeah, that will work, IF the video on the net is in a windows acceptable format, like WMV, or an AVI package that your system has a codec for, otherwise, it will crash. There are no easy answers.

Diamonddrake 397 Master Poster

as per the original question. Windows Media Player cannot stream videos from youtube because windows don't have a FLV codec. and they won't make on because Microsoft and Adobe and a falling out a few years back, and since Adobe acquired the flash platform and refused to give Microsoft the rights to use it on thier system. Microsoft created silverlight, and thus, Flash Video Integration into windows won't be around legally for quite some time. Sorry.

BUT

if you want to just load a flash plugin com object into you C# windows form app and load into that a swf movie that plays FLV, you can then migrate flv videos from youtube to your application.

But that's all the help I can provide as I am really busy right not, and this is a very complicated project.

Diamonddrake 397 Master Poster

I would like to create a overridden picturebox control that accepts a colormatrix as a property, and when the picturebox is drawn it uses that colormatrix. This is to cut down on drawimage GDI calls that are slowing down my app. I would love to turn 2 into 1, and cut down form 3 image objects to 1. But when decompiling the Windows.Forms.PictureBox I find that its onPaint method is an override of the Windows.Forms.Control's onPaint method and its don't a hefty amount of sealed work that I can't seem to compile. here is the original onPaint

protected override void OnPaint(PaintEventArgs pe)
        {
            if (this.pictureBoxState[0x20])
            {
                try
                {
                    if (this.WaitOnLoad)
                    {
                        this.Load();
                    }
                    else
                    {
                        this.LoadAsync();
                    }
                }
                catch (Exception exception)
                {
                    if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                    {
                        throw;
                    }
                    this.image = this.ErrorImage;
                }
            }
            if (this.image != null)
            {
                this.Animate();
                ImageAnimator.UpdateFrames();
                Rectangle rect = (this.imageInstallationType == ImageInstallationType.ErrorOrInitial) ? this.ImageRectangleFromSizeMode(PictureBoxSizeMode.CenterImage) : this.ImageRectangle;
                pe.Graphics.DrawImage(this.image, rect);
            }
            base.OnPaint(pe);
        }

and here is what I want it to look like

protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
        {
            if (base.pictureBoxState[0x20])
            {
                try
                {
                    if (this.WaitOnLoad)
                    {
                        this.Load();
                    }
                    else
                    {
                        this.LoadAsync();
                    }
                }
                catch (Exception exception)
                {
                    if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                    {
                        throw;
                    }
                    base.image = this.ErrorImage;
                }
            }
            if (base.image != null)
            {
                base.Animate();
                ImageAnimator.UpdateFrames();
                Rectangle rect = (base.imageInstallationType == base.ImageInstallationType.ErrorOrInitial) ? base.ImageRectangleFromSizeMode(PictureBoxSizeMode.CenterImage) : base.ImageRectangle;
                if (PaintCM == new ColorMatrix())
                {
                    pe.Graphics.DrawImage(base.image, rect);
                }
                else
                {

                    ImageAttributes ia = new ImageAttributes();
                    ia.SetColorMatrix(PaintCM);
 
                    pe.Graphics.DrawImage(base.image, rect, 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, ia);
                }
            }
            base.OnPaint(pe);
        }

Problem is, It …

Diamonddrake 397 Master Poster

since I am using a zoomed picturebox, the resulting appearance is identical. I am using that crop picture box i was working on, that allows you to go back and fourth between the cropped and uncropped image, and proper cropping requires the real full size image, unless I want it to only be approximate. So I'm looking into a work around for the issues it creates. And also I am looking to expand that cropped picturebox control to support zoomed, 1:1 and maybe 1:3 viewing sizes with the ability to pan, That's a whole new ball game there. Like I said, its a really ambitious project. But once its done, Hopefully it will be a worthwhile adventure. So many features to implement.

Thanks again, expect to see a few more threads pop up from me as the program carries on in development.

Diamonddrake 397 Master Poster

I tried this
when the image loads in, create a WorkingImage that is 1/4 the size or so, display that image scaled to fit in the image viewer picturebox. then use that image for the transformations preview it is much faster, and either wait to apply the transformations to the full image until the image is saved, or alternatively, like in my application where you might need the transformed full image, periodically update a fullsized transformed image on a separate thread.

Sill working the bugs out, but it seems to give that performance burst that makes everything feel fluid.

Diamonddrake 397 Master Poster

you could in theory take your image and load it in as a byte array, not as an image, sift through the bytes and find the start of the image data, then apply them there, but idk what the results would be. but other than that. there isn't sorry.

TotoTitus commented: Very relevant. +1
Diamonddrake 397 Master Poster

I am applying a colormatrix object as an imageattribute to drawimage. which requires a new image everytime, and reading the source image everytime.

I have a method that takes a source image, and the 3 values of each slider, creates a single color matrix from that data creates a bitmap image, draws to it the originonal image with the colormatrix image attribute, then returns that image. the image is set to a picturebox and the picturebox is refreshed.

given that situation how could I improve?

Diamonddrake 397 Master Poster

your extention was jpg but the image was NOT a jpeg. extensions mean nothing. Listen.

1. If you want to preserve your changes you cannot compress it, because compression codecs change those values.

2. Saving as a BMP is uncompressed, So it will work, but the file will be big.

3. if the file is big, then its uncompressed, and your data is preserved, if the file is small, then its compressed and you WILL LOOSE YOUR CHANGES

sorry that's how Imaging works.

Diamonddrake 397 Master Poster

I think lightroom might be magic, as it has 60 sliders ( I counted them just now) and all of them are live, real time instant display of change, even a live histogram that changes with the sliders. And thats on a 32mb digital negative 32 bit image over 4000px wide taken with a Nikon SLR cam. idk how they do it. But I managed to create a color matrix that handles brighness, saturation, and contrast simultaneously and its not blazing fast, but its almost real time. so if I could just come up with a smoothing/sharpening effect that is semi-real time. with what I have, I would be satisfied. Kudos to the adobe lightroom team. after all my research, I have found nothing of how they do it.

Diamonddrake 397 Master Poster

after a few hours of research, I got the colormatix down, figured out a good matrix that performs accurate brightness and contrast in 1 pass. and i am working on more, When I finish the class i will likely post it on code project. however, I feel like I am a long way away, as I keep finding new problems with tackling a hugely pretentious project like this one.

Thanks guys!

Diamonddrake 397 Master Poster

if you have ever used adobe lightroom you would have noticed that there is an awesome sidebar with 15 or so sliders on it. they can all be adjusted from the same screen and you watch as they edit the image in real time. This is what I am trying to replicate. and here is where my problem lies...

I have written some methods that apply color matrices to an image and return that transformed image. works great. i can put a slider on drag the tick and watch the brightness change ect. but in order for the transformation to be accurate, I must always pass the source image to each one. not the edited image. let me elaborate.

say I increase the brightness and contrast of an image using a complicated color matrix. but now i want to increase the saturation a bit, so i pass the new adjusted image into my hsl class and return a new image, now the image has been changed twice. If I feel like the image is too bright, and I want to move the brighness slider down. I the value assigned to the slider will be wrong, and its effects not accurate using the newly edited image, I must use the original image. so that means I must store and reapply the saturation values, but this means, given all the adjustments my final program will be using will have to be applied every time, this will be sluggish, and not …

Diamonddrake 397 Master Poster

the idea behind JPEG image compression is that it removes color differences that are not apparent by the human eye. If you really want a full quality picture you might want to always save to bmp or png24 regardless of source type.

jpeg compression looks good, and makes for a good file size, but if your goal is just to preserve bytes written into your image, you probably will loose it during the compression. Sorry. its still not clear to me what your goal is.

Diamonddrake 397 Master Poster

I ment size as in file size not dimensions. sorry.

// We will store the correct image codec in this object
            ImageCodecInfo iciJpegCodec = null;
            // This will specify the image quality to the encoder
            EncoderParameter epQuality = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (int)80);//set quality here
            // Get all image codecs that are available
            ImageCodecInfo[] iciCodecs = ImageCodecInfo.GetImageEncoders();
            // Store the quality parameter in the list of encoder parameters
            EncoderParameters epParameters = new EncoderParameters(1);
            epParameters.Param[0] = epQuality;

            // Loop through all the image codecs
            for (int i = 0; i < iciCodecs.Length; i++)
            {
                // Until the one that we are interested in is found, which is image/jpeg
                if (iciCodecs[i].MimeType == "image/jpeg")
                {
                    iciJpegCodec = iciCodecs[i];
                    break;
                }
            }
         
//now save
                yourImage.Save(filepath, iciJpegCodec, epParameters);

I borrowed this code from somewhere a long time ago, i don't remember where. there are other ways. but this one always worked for me.

Diamonddrake 397 Master Poster

if the image is a different size, its probably the compression level. when you save your bitmap, if you save it as a jpeg file, you can alter its compression methods, changing its filesize, if you just call save, it uses the default. which might be different from the source image.

Diamonddrake 397 Master Poster

Bop powell is a cool guy and all, but his take on Contrast sucks. If anyone knows a good contrast matrix I would love to have it. I am going to play around and see what I can come up with. But just multiplying all the intensities results in a brighter image, not just a higher contrast image. arg.

And thanks for the link scott. I downloaded it. I will see what I can shift through. I am having some performance issues with my code. But I will be starting a new thread with that as soon as I get all my matrices sorted out.

thanks.

Diamonddrake 397 Master Poster

Also it would appear the the source code to paint.net is no longer available.

Diamonddrake 397 Master Poster

paint.net is awesome, but Its geared toward creating images, I am looking for photo optimization like things. Auto contrast/color , soften, burned edges, type things. I will look into paint.net to see how how they do things, but I was just asking incase someone had a great free library they would like to get used or some code snippets.

Im not into thirdparty paid stuff, I am actually hoping to go standalone with this one and not even have an installer for it. Thanks for the link dan but i'm awful at math. I have to draw things out on paper and hangout with a calculator when I am writing my controls, But I will look into it.

thanks.

Diamonddrake 397 Master Poster

I am working on a little image program aimed at having a simple interface but a strong backend. Its mostly just for basic bulk settings and looping through files. but will allow for all the images to be loaded in a thumbnail strip and be able to be edited before all the actual work happens.

that's the setting, here's the question. Anyone have any interesting image manipulation snippets laying around? I'm not sure what all I am interested in seeing it do. I just know I want it to do more. It currently crops, flips horizontal and vertical, adjusts hue saturation and luminance and rotates.

I'm thinking maybe some white balance stuff or really any kind of suggestion or code snippet. I just want more options, I'm thinking about maybe a plug ins interface. but basic filter or image tricks would be nice for now.

Thanks!

Diamonddrake 397 Master Poster

Thanks, everything went well this time around. I created an enum to hold the resize direction and some methods the automatically set the cursor icon and return how the rect needs to be resized. added a crop function that returns a cropped bitmap and optionally copies it to the clipboard.

Its practically a finished control. But i have more plans for it. I thank you again for your assistance. and I hope you will allow me to thank you in the "special thanks" section of the about box for my finished app.

Diamonddrake 397 Master Poster

Take a look at this thread - http://bytes.com/topic/c-sharp/answers/268661-how-upload-file-via-c-code

Looks like exactly what I wanted. i still have to test it. but Seems sound. Thanks!

Diamonddrake 397 Master Poster

ok, wow. that fixes everything. i wasn't sure til the end. but that's brilliant. immediately convert everything to the image coordinates and work with that and just don't worry about the selection rectangle as it exists on the picture control because just converting it to zoomed takes care of it.

I will likely run into some issues bringing this control all the way through. So I will post back here with further questions.

Thanks!

Diamonddrake 397 Master Poster

Thanks for the work you put into this, I am about to read through it all and see all what has been changed. I will post back with my questions. I know I will have some. thanks again.

Diamonddrake 397 Master Poster

I am able to post data to a form so long as its strings. by creating a dictinary of keys and values, then creating a string in the style of key+ "=" + value "+ & repeat. then passing it to a method kinda like

private string PostData(string url, string postData)
{
HttpWebRequest request=null;

Uri uri = new Uri(url);
request = (HttpWebRequest) WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
using(Stream writeStream = request.GetRequestStream())
{
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(postData);
writeStream.Write(bytes, 0, bytes.Length);
}

string result=string.Empty;
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader readStream = new StreamReader (responseStream, Encoding.UTF8))
{
result = readStream.ReadToEnd();
}
}
}
return result;

but this doesn't work for files.

I am working on an application that is going to make it DIRT simple for my friends and family to quickly edit, crop, resize, and optimize for email, pictures from a digital camera. then using my web server for my website, so the users don't have to worry about smtp server stuff, the app will automatically zip and email the pictures just by specifying the address to send it to.

i have finished a asp file that will accept a multipart form's post data. automatically uploading any "file" type data to a temp diretory, and then emailing the files to the email address sent to it. then deleting the temp data. It works great so long as I use …

Diamonddrake 397 Master Poster

Here is the control in an example project. I know there has to be some simple solution. but I might have to give up and just allow the rectangle to be re sized and not moved.

Diamonddrake 397 Master Poster

sending information over a network is done using a stream. you write bytes to it. these bytes can be anything. Text, audio, pictures, whatever. Its simple, just find a way to compress your audio, but once compressed, instead of writing it to a file stream, write it to your network stream.

then on the receiving end, decompress you buffer and use it. If it is more important the audio be fast and not perfect then I suggest UDP over TCP but that's trivial. I don't have any free time to provide any code or further suggestions, but I hope this helps.

Diamonddrake 397 Master Poster

ok. here is the updated control. Now compiles. but the move still doesn't work right.

again, some insight would really be appreciated.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Learning_Ruber_Band_selection
{
    class EnhancedPictureBox : PictureBox
    {

        public EnhancedPictureBox()
        {
            this.Paint += new PaintEventHandler(PictureBox1_Paint);
            this.MouseDown += new MouseEventHandler(PictureBox1_MouseDown);
            this.MouseMove += new MouseEventHandler(PictureBox1_MouseMove);
            this.MouseUp += new MouseEventHandler(PictureBox1_MouseUp);

        }

       #region points translations modified from ryshad's post

       private Point ConvertPointToImage(Point clicked)
       {
           if (this.SizeMode == PictureBoxSizeMode.Zoom)
           {
               //get size of original image
               Size size = this.Image.Size;
               //get value of scale
               float num = Math.Min((float)(((float)ClientRectangle.Width) / ((float)size.Width)), (float)(((float)ClientRectangle.Height) / ((float)size.Height)));

               //scale size to calculate translation
               size.Width = (int)(size.Width * num);
               size.Height = (int)(size.Height * num);

               //reverse translation
               clicked.X -= (ClientRectangle.Width - size.Width) / 2;
               clicked.Y -= (ClientRectangle.Height - size.Height) / 2;

               //reverse scale
               clicked.X = (int)(clicked.X / num);
               clicked.Y = (int)(clicked.Y / num);

               //return image coordinates
               return clicked;
           }
           else if (this.SizeMode == PictureBoxSizeMode.CenterImage)
           {
               //how the centering works
               //rectangle.X += (rectangle.Width - this.image.Width) / 2;
               // rectangle.Y += (rectangle.Height - this.image.Height) / 2;
               //--

               // got this online
               // - http://www.codeproject.com/KB/miscctrl/PictureBoxExtended.aspx

 
               int diffWidth = this.ClientRectangle.Width - Image.Width;
               int diffHeight = this.ClientRectangle.Height - Image.Height;

               diffWidth /= 2;
               diffHeight /= 2;

               clicked.X -= diffWidth;
               clicked.Y -= diffHeight;

               return clicked;

           }
           else if (this.SizeMode == PictureBoxSizeMode.StretchImage)
           {
               // Make sure our control width and height are not 0
               if (Width == 0 || Height == 0) return clicked;
               // First, get the ratio (image to …
Diamonddrake 397 Master Poster

Sorry. I accidentally removed a block of code with those 2 methods. they are just for the actual cropping effect and not for the section problem I am having. you can remove those 2 whole if statements that do the cropping and then go from there. I will post back a fixed version of that later, right now i have to drive my girlfriend to work.

Diamonddrake 397 Master Poster

seriously no suggestions?

Diamonddrake 397 Master Poster

It is complicated. I can't say that its all that elegant code. but It seems to be working except some minor problems. here is the entire extended picture box class just add it to a project, add it to a form, and put an image on its Image property. It has no error handling so be mindful of possibilities that it may crash.

remember to set its sizeMode to "zoom".

What I am trying to do is have a drawable, resizeable, moveable selection rectangle that works with a zoomed picture box that won't let the selection rectangle move off the form its about 600 lines. i have worked hard on it. if I could get it working right and bug free i would be thrilled.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Learning_Ruber_Band_selection
{
    class EnhancedPictureBox : PictureBox
    {

        public EnhancedPictureBox()
        {
            this.Paint += new PaintEventHandler(PictureBox1_Paint);
            this.MouseDown += new MouseEventHandler(PictureBox1_MouseDown);
            this.MouseMove += new MouseEventHandler(PictureBox1_MouseMove);
            this.MouseUp += new MouseEventHandler(PictureBox1_MouseUp);

        }

       #region points translations modified from ryshad's post

       private Point ConvertPointToImage(Point clicked)
       {
           if (this.SizeMode != PictureBoxSizeMode.Zoom)
           {
               return clicked;
           }
           //get size of original image
           Size size = this.Image.Size;
           //get value of scale
           float num = Math.Min((float)(((float)ClientRectangle.Width) / ((float)size.Width)), (float)(((float)ClientRectangle.Height) / ((float)size.Height)));

           //scale size to calculate translation
           size.Width = (int)(size.Width * num);
           size.Height = (int)(size.Height * num);

           //reverse translation
           clicked.X -= (ClientRectangle.Width - size.Width) / 2;
           clicked.Y -= (ClientRectangle.Height - size.Height) / 2;

           //reverse scale
           clicked.X = (int)(clicked.X / num); …
Diamonddrake 397 Master Poster

I am working on a picturebox that adds a in-depth cropping feature, I am a centered junkie, that is to say I don't find left justified images aesthetically pleasing. I just have to have everything centered. Add to this that the zoom mode of the picture box ensures that the image will be show in its entirety and be centered. I can't pass that up.

I have worked it out to perform a simple drag and drop selection rectangle system. Once the rectangle it drawn you can resize it by simply clicking on a edge of the rectangle and dragging it. If you click on the center of the rectangle you can move the entire rectangle.

My problem is that if you move the rectangle you can drag it off the image, I would like it to stop once the rectangle reaches the edge. I have worked out a way to do this, but it is really buggy and over all just doesn't work right. below is an excerpt showing how I am doing it. if anyone show me whats wrong, or help me find another method I would appreciate it.

//some vars
        bool m_mover = false;
        Size m_mover_size;
        Point m_distance;


//mouse down event handler
Rectangle mini = new Rectangle(selection.Location.X + 4, selection.Location.Y + 4, selection.Width - 8, selection.Height - 8);

            if (mini.Contains(e.Location))
            {
                m_mover = true;
                m_distance = new Point(e.Location.X - selection.Location.X, e.Location.Y - selection.Location.Y);
                m_mover_size = new Size(selection.Width, selection.Height);
            }


// THIS IS THE ON …
Diamonddrake 397 Master Poster

Thanks! I haven't tested it yet. But everything looks right. Thank you very much! I never did very well with geometry, and I had been struggling with this for a few hours before I decided I needed to ask for help. It looks so much simpler now, broken into commented steps.

Thanks again!

Diamonddrake 397 Master Poster

Ryshad, That is some beautiful code. And I appreciate the time you put into it. But I am afraid I didn't describe my problem correctly. I am having trouble going from the actual Image coordinates to the Picturebox coordinates as zoomed. That is, exactly what your method there does, just reversed. I want it to accept an Image coordinate and return a zoomed picturebox coordinate.

I need it so that I can keep a selection rectangle from going outside of the image. I have most of the code worked out for the most part. But I'm having trouble with this. Thanks for the efforts you have put in.

and ddanbe, I glanced at that code snippet and I don't have time to run through it to see what it does right now, but I will later tonight. I would really like to get this control taken care of. Its for a little freeware app I am working on to make it easier to quickly and easily edit and mail pictures to your friends and family!

Diamonddrake 397 Master Poster

I need to be able to take a point on an image and convert it into a point relative to a picturebox with the pictureSizeMode set to zoom

here is the code that the picturebox uses to scale and center the image

Size size = this.image.Size;
 float num = Math.Min((float)(((float)base.ClientRectangle.Width) / ((float)size.Width)), (float)(((float)base.ClientRectangle.Height) / ((float)size.Height)));
 rectangle.Width = (int)(size.Width * num);
rectangle.Height = (int)(size.Height * num);
rectangle.X = (base.ClientRectangle.Width - rectangle.Width) / 2;
 rectangle.Y = (base.ClientRectangle.Height - rectangle.Height) / 2;
return rectangle;

I realize this returns a rectangle, but I need it to accept a point for example 0,0 on an image, if the image was tall it would be scaled by height so the the Y would stay 0 but if the image was say 359px wide and the picuture box was 417 pixles wide the point would go from 0,0 to 35,0.

I can get it to work so long as I use 0,0 but if I need other points I cant seem to make it happen. I'm not very good a geometry.

Any help would be appreciated.

Diamonddrake 397 Master Poster

Nevermind. I was over thinking it. Trick was to divide the ratio by the size of the rectangle. Now i have a more complicated problem of keeping the selection rectangle from running off the image.

Diamonddrake 397 Master Poster

I have inherited from a picturebox and modified it to allow a selection rectangle to be drawn. Everything works well, except I would like for it to work in all sizeModes. center is simple, normal is simple. but I cant' seem to get "Zoom" to work. I have used reflector to strip the out the code that is responsible for the zoom rectangle in the picturebox. Its simple, it just devides the client width by the image width and the client height by the image high and gets the smaller value and scales by that.

When I try to do this with my rectangle I don't get the correct size,

I'm not the best at math, especially geometry. but this seems like it should be more simple.

The image is centered in the control, and scaled to fit. I draw a rectangle on the control representing a crop region. the rectangle then needs to be translated to the acutall image coordinates. I found a codeproject site that translates points. but It seems to be off, and I can't seem to get the size of the rectangle right.

Any help would be appreciated.

Diamonddrake 397 Master Poster

Short answer: No.

you could write try catch bocks around all the code you write, and then create a method tha takes an exception param, and call it in all the catch blocks passing to it the exception that caused the problem. BUT its not a good idea. try catch is used only when there is the chance that there will be an error that you can't handle manually. Most errors should be prevented using if or switch blocks. try catch is slow. you can't sandbox your entire app without adding an overhead.

Diamonddrake 397 Master Poster

I don't know if it exists in the compact framework. But you could always just do it manually, Its simple. just replace certain characters in the string with its url-Encoded equivalent.

Diamonddrake 397 Master Poster

I'm not sure what you mean about it requiring that you override some methods. But that's not your problem. You added a reference to the debug dll of the class library, when your class library is in the same project you add a reference using the "project" tab of the add reference dialog. I made this switch and now everything works as it should and the logincontrol appears in the toolbox at the top.

here is the fixed project and a screen cap.

Diamonddrake 397 Master Poster

Do your controls inherit from UserControl or Control? if they don't inherit from one of those they can't be added.

Furthermore, Its likely that you custom control doesn't have a public constructor. and there should be a constructor that takes 0 args, even if your control needs to take some args, in order for the toolbox to work right there needs to be one with 0 args.

hope this helps. Its hard to help without seeing the code.

try this, create a new project, add a new class call it mybutton, then change it to inherit from System.Windows.Forms.Button save it and compile. then close the empty for that appears, and look in the tool box, at the very top there should be a gear icon with "mybutton" next to it. It should be that simple.

Diamonddrake 397 Master Poster

Depending on your settings it might not. Rightclick on the toolbox and select "choose items" browse to your library and select the controls from it you want to see in the toolbox.

Diamonddrake 397 Master Poster

an Idea would be to draw the graph to a bitmap. Then display the bitmap, and just modify one of those 10,000 zooming picturebox controls floating around the net.

Diamonddrake 397 Master Poster

The idea is at some point you have to interface with the wireless carriers. A gateway is a must, that's how its done. Now if you want tocreate your own gateway, then you have to contact the business departments of all the Wireless Phone companies you want to support and go from there.

But the easiest method is to use email gateways already provided by the phone companies. xxxxxxxxxx@txt.att.net for att. That's how I do it on my site. I have a contact form that allows you to choose email or txt message. I just have a simple if statement that switches out the addy and poof. Easy simple solution.

But if you are really looking to start your own business as a wireless text gateway provider, Looking around in a C# forum isn't going to help you. To handle a serious load you are going to need a team of programmers and custom equipment somewhere near a phone hub.

Text messages are sent using a complicate process that has nothing to do with the internet or standard computer technologies. It all happens on the wireless phone provider's network.

Diamonddrake 397 Master Poster

Instead of reading the bytes and doing the calculation, or by directory, why now go half way, just count all the files to be scanned, then increment it as it finishes files...

DdoubleD's way would be the most accurate, and Ryshad's way would be the fastest, Just counting all the files would be significantly faster than the first method, but more accurate than the second.

Guess its all up to your taste. Speed or accuracy.

Everyone dissed on the file copy and transfer time remaining calculations on XP, so Vista and 7 spend more time calculating the time it will take. Now the time remaining estimation is significantly more accurate, but it takes extra time calculating instead of transferring files, so its actually slower to copy or move files now thanks to that accuracy calculations. - a person like myself, cares about how long it will take only because I wish it would go faster.