Results 1 to 19 of 19

Thread: PictureBox: Scale Width & Height

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    PictureBox: Scale Width & Height

    Hey everyone, once again your help is needed.

    In Visual Basic 6.0 you could set the scale height and width properties of a picturebox, In C# those properties don't exist.


    Could someone please help me set the following properties...

    ScaleHeight = 5356
    ScaleWidth = 5600


    How would I go about doing this.


    Thanks for any help.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: PictureBox: Scale Width & Height

    From MSDN

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    This is making no sense, Could you maybe show me an example for a Picturebox, I'm very new too c#.

    Thanks for any help.

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: PictureBox: Scale Width & Height

    ScaleMode, ScaleWidth, ScaleHeight, ScaleLeft, ScaleTop are no present in .NET.
    Are you drawing in the PictureBox or just Loading Images? Maybe there is another way to do what you need, maybe Using Graphics class.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    I have a list of coordinates which I need to draw a line though each of these X & Y coordinates.

    I have done this in VB but I had to set the scale properties to those in my previous post for it to work.

    There must be a way, why would they take out such a useful property

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    Basically I just want the picturebox to have...

    5356 coordinates High
    5600 coordinates wide

    Anyone got any ideas.

  7. #7
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: PictureBox: Scale Width & Height

    How do you make your drawing? maybe you could get the ratio between the coordinate where you want to draw and your Height/Width, and then use it to get the corresponding position in the PictureBox in Pixels.
    Are you drawing in Paint event? or using Graphics DrawLine method?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    This is my drawing, those values will be different depending on the plot file I load in, I just set out these coordinates to test it before I continue.

    Code:
            private void PB1_Paint(object sender, PaintEventArgs e)
            {
    
                
                PB1.BackColor = Color.White;
    
                e.Graphics.DrawLine(Pens.Black, 3947, 2004, 3947, 2004);
                e.Graphics.DrawLine(Pens.Black, 9868, 7812, 9868, 7812);
                e.Graphics.DrawLine(Pens.Black, 3947, 3122, 3947, 3122);
                e.Graphics.DrawLine(Pens.Black, 8634, 10604, 8634, 10604);
                e.Graphics.DrawLine(Pens.Black, 3454, 4238, 3454, 4238);
                e.Graphics.DrawLine(Pens.Black, 7000, 11398, 7000, 11398);
                e.Graphics.DrawLine(Pens.Black, 2800, 4556, 2800, 4556);
                e.Graphics.DrawLine(Pens.Black, 300, 11398, 300, 11398);
    
            }
    This doesn't draw anything and I assume that is bcos most of those coordinates don't exist.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    Any ideas anyone? this is really important.

    Thanks for any more help.

  10. #10
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: PictureBox: Scale Width & Height

    That code won't draw anything, why are you passing X1 = X2 and Y1 = Y2??
    Origin and target points are the same there.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    Oh yea how stupid of me lol,

    Still I only see one line now, the rest must be off the screen as these coordinates dont exist. Now I'm drawing like this.

    Code:
            private void PB1_Paint(object sender, PaintEventArgs e)
            {
    
                
                PB1.BackColor = Color.White;
    
    
                e.Graphics.DrawLine(Pens.Black, 3947, 3947, 2004, 2004);
                e.Graphics.DrawLine(Pens.Black, 9868, 9868, 7812, 7812);
                e.Graphics.DrawLine(Pens.Black, 3947, 3947, 3122, 3122);
                e.Graphics.DrawLine(Pens.Black, 8634, 8634, 10604, 10604);
                e.Graphics.DrawLine(Pens.Black, 3454, 3454, 4238, 4238);
                e.Graphics.DrawLine(Pens.Black, 7000, 7000, 11398, 11398);
                e.Graphics.DrawLine(Pens.Black, 2800, 2800, 4556, 4556);
                e.Graphics.DrawLine(Pens.Black, 300, 300, 11398, 11398);
    
    
            }

  12. #12
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: PictureBox: Scale Width & Height

    Coordinates are still wrong, you are drawing just inside that line you see because X1 = Y1 and X2 = Y2, I can make an ScaleWidth and ScaleHeight Subs in C# but you have something valid to draw?

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    Ahhh I'm lost then lol, in VB coordinates were just .line x , y but in c# I have for arguments, that would be great if you could do me a sub. I would be really greatful. I'll get back to ya with something valid to draw lol, Ill just see if I can get my head around this.

    Thanks again

  14. #14
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: PictureBox: Scale Width & Height

    Add this on Top (Form level)
    Code:
       private int mScaleWidth  = 5600;
       private int mScaleHeight = 5356;
    Then this is the Paint Event named PaintIt (you can use another name) and a drawLine sub, use this one instead of e.Graphics.DrawLine
    Code:
    	private void PaintIt(object sender, System.Windows.Forms.PaintEventArgs e)
    	{
    		PB1.BackColor = System.Drawing.Color.White;
    		
    		//Square
    		drawLine(e.Graphics, Pens.Black ,   1000, 1000, 2000, 1000);
    		drawLine(e.Graphics, Pens.Black, 2000, 1000, 2000, 2000);
    		drawLine(e.Graphics, Pens.Black, 2000, 2000, 1000, 2000);
    		drawLine(e.Graphics, Pens.Black, 1000, 2000, 1000, 1000);
    	}
    
    	private void drawLine(Graphics Gr,Pen  Pn, int X1, int Y1, int X2, int Y2)
    	{
    		int ScaledX1 = (int) (((float) X1 / mScaleWidth) * PB1.ClientSize.Width);
    		int ScaledX2 = (int) (((float) X2 / mScaleWidth) * PB1.ClientSize.Width);
    		int ScaledY1 = (int) (((float) Y1 / mScaleHeight) * PB1.ClientSize.Height);
    		int ScaledY2 = (int) (((float) Y2 / mScaleHeight) * PB1.ClientSize.Height);
    
    		Gr.DrawLine (Pens.Black ,ScaledX1, ScaledY1, ScaledX2,ScaledY2);
    	}
    That should draw a Square using your coordinate system.
    Last edited by jcis; Jan 17th, 2007 at 01:39 PM.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    Thank you soooo much for all of your help, that seems to do what I want. I sort of understand what you have done there now.

    I just have one more problem lol, The coordinates which I will be putting in to this only have two values, 1 of X and 1 of Y.

    I dont see how I can enter just two values as this coordinate system seems different as to VB where .line only wanted those two values.

  16. #16
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: PictureBox: Scale Width & Height

    In VB6 Line method of a Form or PictureBox also uses X1, Y1, X2, Y2
    VB Code:
    1. Picture1.Line (100, 100)-(500, 500)
    So I think your VB code is doing something else, can you post some of it using VBCODE tags?

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    VB Code:
    1. If Machine = 5 And SentXys > 1 Then
    2. YMaths = (DrawYlength - (DrawY + DrawChange))
    3. YMaths2 = ((YMaths / 10) * 4)
    4. DrawY = (BaseLine - YMaths2)
    5. DrawX = ((DrawX / 10) * 4)
    6.  
    7. If Delay = True Then
    8.         dblClock = Timer
    9.         'Delay the drawing
    10.         While Timer < dblClock + 0.1
    11.             DrawAPlot2.XY5Machine.Line -(DrawX, DrawY)
    12.             DoEvents
    13.         Wend
    14. Else
    15.     DrawAPlot2.XY5Machine.Line -(DrawX, DrawY)
    16. End If

    XY5Machine is the name of the PictureBox,

    I think I should just give up lol seems impossible to get this right

  18. #18
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: PictureBox: Scale Width & Height

    .Line -(DrawX, DrawY)
    That Uses 2 parameters because it draws from the last position to the new Point, the Origin coordinates are not explicit because the Origin is the coordinate where the last line ended.
    You can achieve the same if you use the last X2, and Y2 values as X1 and Y1 in the next line, see my square, Each X1, Y1 are equal to X2, Y2 in the previous Line.
    You can also use the method: Graphics.drawLines, it takes an array of Points (X,Y) as parameter and creates lines that Join them.
    About your VB code it is not very descriptive, you didn't post events and each object/variable declaration, so i can't Run it as it is there.
    Last edited by jcis; Jan 17th, 2007 at 02:44 PM.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: PictureBox: Scale Width & Height

    Thanks for all the help it really is appreciated but I think this project is way beyond my capability at the moment lol so I think I will come back to it once I have more experience.

    Sorry to waste your time, and thanks again for all you help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width