By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,884 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,884 IT Pros & Developers. It's quick & easy.

graphics in vb.net

P: 19
I need someone to make an example of how to create a graphics window in VB.net 2008.

I understand the basics of how to draw a rectangle and lines etc.

What I need is an example of how to make a window that goes in a form that does the following:

1. When the application is run, the form has a graphics area within the form (not the entire form) colored white.

2. Two text boxes (not in the graphics area) for data entry used to define the start and end of a line.

3. Three text boxes (also not in the graphics area) to define the center of a circle and the radius of the circle.

3. A button that if the text boxes have dimensions in them and the user presses the button the line and circle will be drawn in the graphics area.

4. If the dimensions of the line or circle would be beyond the graphics area, the line and circle should be drawn but they should not extend beyond the graphics area. This need to work for any object drawn in the graphics area without computing the limits of the object to fit in the area.

5. A control to set the scale of the display in the graphics area so that the user can zoom in or out.

6. A control to pan the graphics area so that the user may have a close look at small area of the graphics window. This might be done with scroll bars on the borders of a window, or mouse action in the graphics area.

The idea of this project is, I have some data that I want to draw graphs of so I need a window area to draw them in. I did some experiments using basic rectangles and lines using GDI but I found that if the graph wend outside the rectangle it just drew it on the form, so I need some help to make a window to draw in.

thankssssssss
Nov 5 '08 #1
Share this Question
Share on Google+
8 Replies


Plater
Expert 5K+
P: 7,872
Are you using DirectX, or just the built in Graphics object?
If it's jsut the built in graphics object (or either I suppose?), just add a Panel control to your form and do your drawing on THAT object.
Your drawing won't go outside the bounds of the Panel object.
Nov 10 '08 #2

P: 19
Are you using DirectX, or just the built in Graphics object?
If it's jsut the built in graphics object (or either I suppose?), just add a Panel control to your form and do your drawing on THAT object.
Your drawing won't go outside the bounds of the Panel object.
I m not using DirectX ,..just Graphics Object..Thank u for replying
i tried your suggestion but it is not working,After that i used picture on my form but still drawing is going beyond the area of picturebox on my form.
Nov 11 '08 #3

Plater
Expert 5K+
P: 7,872
Well, lets see some code, if you were truely drawing on the Graphics object for the child control (panel, picturebox, etc) then the drawing should not have extended past its bounds
Nov 11 '08 #4

P: 19
Well thank u for replying once again ... this is my code i had done in one of module having another form that contain picture box on which i had to draw.
Expand|Select|Wrap|Line Numbers
  1.  Sub Column_Draw(ByVal DrawControl As Graphics, ByVal DrawStr As String)
  2.         Dim NMAXX,NMAXY,NMINX,NMINY  As Single
  3.         Dim Dc,ds  As DAO.Recordset
  4.         Dim dss As DAO.Recordset
  5.         Dim X, Y As Single
  6.       DrawControl.ScaleTransform(-1, 1)
  7.         DrawControl.TranslateTransform(-20, VertLineLength + 200)
  8.         DrawControl.RotateTransform(180)
  9.         Dc = CurDb.OpenRecordset("Drawdata", DAO.RecordsetTypeEnum.dbOpenDynaset)
  10.         ds = CurDb.OpenRecordset("Columns", DAO.RecordsetTypeEnum.dbOpenDynaset)
  11.         dss = CurDb.OpenRecordset("Columns", DAO.RecordsetTypeEnum.dbOpenDynaset)
  12.         If Not Zoom Then
  13.             MaxMin(ds, NMAXX, NMAXY, NMINX, NMINY)
  14.             'MAX = IIf(NMAXX > NMAXY, NMAXX, NMAXY)
  15.             If NMAXX > NMAXY Then
  16.                 Max1 = NMAXX
  17.             Else
  18.                 Max1 = NMAXY
  19.             End If
  20.             'MIN = IIf(NMINX < NMINY, NMINX, NMINY)
  21.             'MIN = IIf(NMINX < NMINY, NMINX, NMINY)
  22.             If NMINX < NMINY Then
  23.                 Min1 = NMINX
  24.             Else
  25.                 Min1 = NMINY
  26.             End If
  27.         End If
  28.         ds.MoveFirst()
  29.         While Not (ds.EOF)
  30.             System.Windows.Forms.Application.DoEvents()
  31.             If ((ds.Fields(4).Value <> "" And ds.Fields(5).Value <> "")) Then 'Condition to bypass column whose position not defined
  32.                 X = ds.Fields(4).Value
  33.                 Y = ds.Fields(5).Value
  34.                 FlushDistances(ds, X, Y)
  35.                 If StrComp(Left(ds.Fields(0).Value, 1), "C") = 0 Then
  36.                     Select Case ds.Fields(1).Value
  37.                         Case "H"
  38.                             DrawControl.DrawLine(Pens.Black, CInt(X - ds.Fields(2).Value / 2), CInt(Y - ds.Fields(3).Value / 2), CInt(X + ds.Fields(2).Value / 2), CInt(Y + ds.Fields(3).Value / 2))
  39.                         Case "L"
  40.                             DrawControl.DrawLine(Pens.Black, CInt(X - ds.Fields(2).Value / 2), CInt(Y - ds.Fields(3).Value / 2), CInt(X + ds.Fields(2).Value / 2), CInt(Y + ds.Fields(3).Value / 2))
  41.                             X = ds.Fields(4).Value
  42.                             Y = ds.Fields(5).Value
  43.                             FlushDistancesL(ds, X, Y)
  44.                             DrawControl.DrawLine(Pens.Black, CInt(X - ds.Fields(3).Value / 2), CInt(Y - ds.Fields(17).Value / 2), CInt(X + ds.Fields(3).Value / 2), CInt(Y + ds.Fields(17).Value / 2))
  45.                     End Select
  46.                 Else
  47.                     Select Case ds.Fields(1).Value
  48.                         Case "H"
  49.                             DrawControl.DrawRectangle(Pens.Red, CInt(X - ds.Fields(2).Value / 2), CInt(Y - ds.Fields(3).Value / 2) - CInt(X + ds.Fields(2).Value / 2), CInt(Y + ds.Fields(3).Value / 2), B)
  50.                     End Select
  51.                 End If
  52.                 If Enlarge Or Main Then
  53.                     Column_Dis(ds.Fields(4).Value + ds.Fields(2).Value / 2, ds.Fields(5).Value - ds.Fields(3).Value / 2, ds.Fields(0).Value, DrawControl)
  54.                 End If
  55.             End If
  56.             ds.MoveNext()
  57.         End While
  58.         CurDb.Execute(Updateqery1)
  59.         CurDb.Execute(Updateqery2)
  60.         While Not Dc.EOF
  61.             System.Windows.Forms.Application.DoEvents()
  62.             DrawControl.DrawLine(Pens.Blue, CInt(Dc.Fields(4).Value), CInt(Dc.Fields(5).Value), CInt(Dc.Fields(6).Value), CInt(Dc.Fields(7).Value))
  63.             Dc.MoveNext()
  64.         End While
  65.         ds.Close()
  66.         Dc.Close()
  67.     End Sub
  68.  
now my problem is that if i give a larger value than my line goes out of bounds,i want that it remains in picture box whether value is small or large and it autosize itself according to value.
Nov 12 '08 #5

Plater
Expert 5K+
P: 7,872
Wait are you saying that the drawn line goes out of the visible area?
I thought you were saying that it leaves the control and draws on another control.
This is an entirely different issue, you should be able to resize the control based on the input lengths of the lines you wish to draw. Just compute if your line is bigger then the control can handle, and then resize it?
Nov 12 '08 #6

P: 19
Wait are you saying that the drawn line goes out of the visible area?
I thought you were saying that it leaves the control and draws on another control.
This is an entirely different issue, you should be able to resize the control based on the input lengths of the lines you wish to draw. Just compute if your line is bigger then the control can handle, and then resize it?
Yes ,that is exactly what i want to say that drawn lines goes out of visible area,
it will be very helpful for me if u can let me know how to this,also if some sample codes.thanku for replying.
Nov 13 '08 #7

Plater
Expert 5K+
P: 7,872
Sure?
How aboue this Psuedo code:
if (myline.XLength > myDrawingArea.XLength)
{
myDrawingArea.XLength = myline.XLength + 10;
}
Nov 13 '08 #8

P: 19
Sure?
How aboue this Psuedo code:
if (myline.XLength > myDrawingArea.XLength)
{
myDrawingArea.XLength = myline.XLength + 10;
}
thank you for replying....
this is difficult for me understand what this pseudo code suggest.
suppose i want to draw 2 rectangles having height and width 300 and 300 and join them by a line of 8000 obviously it will go out of bounds i.e it will be outside of visible area ,i want them within picture box no matter how much is the value .plz send some sample codes in vb.net ,
Nov 15 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.