473,847 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

graphics in vb.net

19 New Member
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 3140
Plater
7,872 Recognized Expert Expert
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
Abhiraj Chauhan
19 New Member
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 Recognized Expert Expert
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
Abhiraj Chauhan
19 New Member
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 Recognized Expert Expert
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
Abhiraj Chauhan
19 New Member
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 Recognized Expert Expert
Sure?
How aboue this Psuedo code:
if (myline.XLength > myDrawingArea.X Length)
{
myDrawingArea.X Length = myline.XLength + 10;
}
Nov 13 '08 #8
Abhiraj Chauhan
19 New Member
Sure?
How aboue this Psuedo code:
if (myline.XLength > myDrawingArea.X Length)
{
myDrawingArea.X Length = 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
3390
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 that all data is scaled to and rendered on, and I display a smaller "window" of the canvas that the user can page through left and right. I've been able to scale my data (for the purposes of this discussion, x values are 0 - 2PI and y values...
12
2392
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 graphics object of the form/pictureBox. Should It be better if make a graphics object from my pictureBox in load event handler of the form and store it as member variable of the form , make
2
3611
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 = new Graphics //SC // first of all there is no constructor for Graphics // so in the Form_Paint I use instead:
14
3114
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 to do this? E.g. I want to be able to graph a function. At this point I'm not up to a level in C++ where I want to start learning Visual C++ so I don't want to go that route. Thanks
5
27173
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 e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat) e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2, TheHeight1 + (390 + yPos))
6
3251
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 (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
12
3611
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 utilities that allows you to view them with live rotation in a web browser. Also, it includes a introductory tutorial to POV-Ray.
6
1702
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 all the properties of the old graphics object (like PageUnit and InterpolationMode...) Can I do that without setting them all one at a time?
9
2669
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() From the Standard CreateGraphics() function the code below works
0
9734
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10991
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10653
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10347
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9490
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7061
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5915
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4129
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3168
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.