|
-
Feb 3rd, 2013, 11:11 AM
#1
Thread Starter
New Member
Another Noob ): Button in Form 1 Draw Line in Form 2
Hi, I'm new to visual basic and I have to do an assignment for my class.
What I need to know is how to make a button from Form1 to draw a line on Form2
(I know how to draw the line without paint event and can do it on Form1, so all I need is just the code to make the line show in Form2 instead of Form1)
Just need this question answered so I can continue on ahead with my assignment.
Thanks for your time.
-
Feb 3rd, 2013, 12:26 PM
#2
Re: Another Noob ): Button in Form 1 Draw Line in Form 2
Lots of ways to go here. I would put my line drawing code in a public sub in Form2 and call it from the button click event in Form1. Just prefix your call with the name of the form - something like "Call Form2.MyDrawingSub()".
-
Feb 3rd, 2013, 12:52 PM
#3
Thread Starter
New Member
Re: Another Noob ): Button in Form 1 Draw Line in Form 2
 Originally Posted by paulg4ije
Lots of ways to go here. I would put my line drawing code in a public sub in Form2 and call it from the button click event in Form1. Just prefix your call with the name of the form - something like "Call Form2.MyDrawingSub()".
Thanks for the reply but I can't understand what you said very well (as I said I'm new, like 3 weeks of programming new)
What's happening with the button in Form1 is the line it draws is being drawn in Form1.
I want that line to instead be drawn in Form2 and not be shown in Form1.
-
Feb 3rd, 2013, 01:06 PM
#4
Lively Member
Re: Another Noob ): Button in Form 1 Draw Line in Form 2
Try this:
In button click at Form1:
Code:
Dim SecondForm as New Form2 'you can change Form2 to your second forms name, but its probably Form2
SecondForm.Label1.Text = "Text" 'change this to draw some line or w/e (SecondForm must stay)
And then also if you want to show second form just use SecondForm.Show()
-
Feb 3rd, 2013, 01:15 PM
#5
Thread Starter
New Member
Re: Another Noob ): Button in Form 1 Draw Line in Form 2
 Originally Posted by silentus
Try this:
In button click at Form1:
Code:
Dim SecondForm as New Form2 'you can change Form2 to your second forms name, but its probably Form2
SecondForm.Label1.Text = "Text" 'change this to draw some line or w/e (SecondForm must stay)
And then also if you want to show second form just use SecondForm.Show()
Thanks for the reply.
I know how to put text from Form1 to Form2.
What I want to know is how to put a line in not text.
This is what I wrote in the button for Form 1
Dim grph as Graphics
Dim BlackPen as New Pen(Color.Black)
Dim SecondForm as New Form2
grph = Me.CreateGraphics()
Will use this line below as an example for the line
grph.DrawLine(BlackPen, 0, 0, 500, 500)
Thanks for your help
Last edited by Nayami; Feb 3rd, 2013 at 01:28 PM.
-
Feb 3rd, 2013, 02:50 PM
#6
Thread Starter
New Member
Re: Another Noob ): Button in Form 1 Draw Line in Form 2
Problem Solved! (Finally)
Here is the answer to my question in case someone has the same problem (:
Assuming you have 2 forms up already.
First Form's name is Form1
Second Form's name is Form 2
Put a button in Form1
Double Click the button in Form1
Enter this
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
Dim BlackPen As New Pen(Color.Black)
Form2.Show()
Form2.CreateGraphics.DrawLine(BlackPen, 0, 0, 500, 500)
-
Oct 23rd, 2013, 06:40 AM
#7
New Member
Re: Another Noob ): Button in Form 1 Draw Line in Form 2
Hello silentus,
I' am new in programming vb.
I read this problem because i have the same problem only i have create a bitmap construction.
I have form1 with a button1
If i click the button1 then he must drawing the rectangle in form2 that i have add to my project.
Here what i have making already.
I have try setting form2 at the beginning of the line thats drawing the rectangle bud i have the error message that g is not a member from form2
Can you help me please what i can do to draw the rectangel to form2 ????
thank you for your time
Regards Bert
Public Class Form1
' Declareren van alle variabelen
Dim genrevierkant = New Rectangle(0, (475 + 80) - 100, 475, 40)
Dim titelvierkant = New Rectangle(0, (475 + 80) - 100, 475, 60)
Dim titelplaatsing As New StringFormat
Dim genreplaatsing As New StringFormat
Dim titelkleur As Color = Color.Black
Dim genrekleur As Color = Color.Black
Dim titelfont As Font = New Font("Segoe UI", 14, FontStyle.Bold)
Dim genrefont As Font = New Font("Segoe UI", 12, FontStyle.Bold)
Dim cdhoes As Bitmap
WithEvents documentPrinter As New Printing.PrintDocument
Private Sub btnTekenUitslag_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTekenUitslag.Click
Dim bmp As New Bitmap(476, 475 + 81)
Dim g As Graphics = Graphics.FromImage(bmp)
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
Dim pen As New Pen(Brushes.Black, 1)
g.FillRectangle(Brushes.White, New Rectangle(0, 0, bmp.Width, bmp.Height))
g.DrawRectangle(pen, 0, 80, 475, 475)
Me.BackgroundImage = bmp
cdhoes = bmp
End Sub
End Class
-
Oct 23rd, 2013, 11:41 AM
#8
Re: Another Noob ): Button in Form 1 Draw Line in Form 2
I think you should oppen a separate thread for your issue. That said, you have all your declarations on Form1 so Form2 does not know what you are talking about. Someone sugested before to put the subs that do the work on form2, with all the variables and declarations, and then call that function or sub from Form1
Call Form2.Function()
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|