none
Drawing a rectangle in form2 RRS feed

  • Question

  •  Hello,

    I have one form (form1) with two inputs (textbox) and two buttons.

    button1 is drawing the rectangle and button2 must printing the rectangel and the text from the textboxes on the paper. 

    What i wil is that the drawing a bmp structure is going to form2 

    i wil use form1 only for input the text and clicking the buttons and i will both forms see on the screen when i running the program.

    Now the drawing is going to form1

    Thanks 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






    • Edited by Oettie Sunday, October 20, 2013 4:05 PM
    Friday, October 18, 2013 1:46 PM

Answers

  • I have one form (form1) with two inputs text and two buttons.

    button1 is drawing the rectangle and button2 must printing the rectangel and the text on it.

    What i wil is that the drawing a bmp structure is going to form2 

    i wil use form1 only for input the text and clicking the buttons and i will both forms see on the screen when i running

    See here for some examples of passing data between forms. You need to decide whether the data is passed from form 1 to form 2 when form 2 is created, or form 2 retrieves the data from form 1 after form 2 is opened, or form1 messages form 2 whenever the user clicks the button (it's not clear from your description whether form 2 should be updated with the new information when the user clicks the button, or if a new form 2 should be created).

    Printing is discussed here.

    Friday, October 18, 2013 10:36 PM
  • Hi Bert,

    for me it's not clear if you want to paint on the form or print something. If printing is the second step then first things first.

    I wouldn't paint from one form on the other form. Form2 should paint itself. That's the purpose of encapsulating classes. As it's already been said, you can pass information from Form1 to Form2. So, override OnPaint in Form2. There you can paint. What needs to be painted can be passed via properties to Form2.

    OOP also means: Think of Form2 being an autonomous, parameterized object. From outside (from Form1) only set the parameters.


    Armin

    Sunday, October 20, 2013 9:16 PM
  • I wil click the button at form1 and then must be open form2 and draw the rectangle in the form2.

    In that case you can pass the parameters for the rectangle as arguments to the form 2 constructor, as per the example that I referred to.  Then draw the rectangle in the Paint event of Form2 using those parameters.

    Sunday, October 20, 2013 10:37 PM

All replies

  • Sounds like homework.  You'll have to start this and then post back with specific questions and examples of your code.  You can get help solving a specific problem or understanding a concept, but you'll have to do the work.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, October 18, 2013 8:49 PM
    Moderator
  • I have one form (form1) with two inputs text and two buttons.

    button1 is drawing the rectangle and button2 must printing the rectangel and the text on it.

    What i wil is that the drawing a bmp structure is going to form2 

    i wil use form1 only for input the text and clicking the buttons and i will both forms see on the screen when i running

    See here for some examples of passing data between forms. You need to decide whether the data is passed from form 1 to form 2 when form 2 is created, or form 2 retrieves the data from form 1 after form 2 is opened, or form1 messages form 2 whenever the user clicks the button (it's not clear from your description whether form 2 should be updated with the new information when the user clicks the button, or if a new form 2 should be created).

    Printing is discussed here.

    Friday, October 18, 2013 10:36 PM
  • Hello,

    Its not that i will do nothing bud i'am new if you are so great then give me the solution please.

    see my project already.

    and becarefull with your conclusions !!!!

    regards bert

    Sunday, October 20, 2013 3:17 PM
  • I wil click the button at form1 and then must be open form2 and draw the rectangle in the form2.

    The project is a cd cover see my listing its not finisch already its drawing only a rectangle bud in this 

    situation in form1.

    regards Bert


    Sunday, October 20, 2013 9:10 PM
  • Hi Bert,

    for me it's not clear if you want to paint on the form or print something. If printing is the second step then first things first.

    I wouldn't paint from one form on the other form. Form2 should paint itself. That's the purpose of encapsulating classes. As it's already been said, you can pass information from Form1 to Form2. So, override OnPaint in Form2. There you can paint. What needs to be painted can be passed via properties to Form2.

    OOP also means: Think of Form2 being an autonomous, parameterized object. From outside (from Form1) only set the parameters.


    Armin

    Sunday, October 20, 2013 9:16 PM
  • I wil click the button at form1 and then must be open form2 and draw the rectangle in the form2.

    In that case you can pass the parameters for the rectangle as arguments to the form 2 constructor, as per the example that I referred to.  Then draw the rectangle in the Paint event of Form2 using those parameters.

    Sunday, October 20, 2013 10:37 PM