473,416 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

graphics in vb.net

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
8 3083
Plater
7,872 Expert 4TB
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
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
7,872 Expert 4TB
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
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
7,872 Expert 4TB
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
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
7,872 Expert 4TB
Sure?
How aboue this Psuedo code:
if (myline.XLength > myDrawingArea.XLength)
{
myDrawingArea.XLength = myline.XLength + 10;
}
Nov 13 '08 #8
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

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

Similar topics

2
by: JBiagio | last post by:
Hello All, I am attempting to learn a bit about the GDI+ transforms and charting data and I feel like I'm getting a handle on how the transforms work. My chart object has a large "canvas" bitmap...
12
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the...
2
by: John Bailo | last post by:
I am walking through some of the very first sample code from the book "Beginning .NET Game Programming" from Apress. I identify his sample code with //SC This code puzzles me: Graphics graph...
14
by: Pmb | last post by:
At the moment I'm using Borland's C++ (http://www.borland.com/products/downloads/download_cbuilder.html#) I want to be able to take an array of points and plot them on the screen. Is there a way...
5
by: Charles A. Lackman | last post by:
Hello, I have created a complete PrintDocument and need to create an image from it. How is this done? e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality...
6
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument...
12
by: Xah Lee | last post by:
Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet...
6
by: active | last post by:
I have an image and a graphics object created (FromImage) from that image. I need to create a new image and create a new graphics object from the new image. I want the new graphics object have...
9
by: DaveL | last post by:
hello I have a Bit map 1367 wide 32 high this bitmap contains like 40 separate Images 32x32 I tell it the id*32 to get the approiate Image from the source Bitmap When i CreateGraphics()...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.