Results 1 to 25 of 25

Thread: [RESOLVED] [:: A new Form with a new Panel and a new Picturebox on it ::]

  1. #1

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Resolved [RESOLVED] [:: A new Form with a new Panel and a new Picturebox on it ::]

    Hello all,

    As I am very new to VB 2010, I am facing lot of problems.

    I want to open a new form with a new panel and a new picture box on it when clicked a button.

    I wrote:

    Dim MyForm As New Form()
    Dim MyPanel As New Panel()
    Dim MyPicBox As New PictureBox()

    MyForm.Width = 680
    MyForm.Height = 480
    MyForm.Text = "Lesson # 1"
    'MyForm.BackgroundImage = My.Resources.Background
    MyForm.FormBorderStyle = Nothing

    MyPanel.Width = 649
    MyPanel.Height = 373
    MyPanel.Location = New Point(19, 55)
    MyPanel.BackColor = Color.White

    MyForm.Show()

    Form is opening when I clicked on the button but it is completely blank. No panel is shown on it.

    can anyone please help?

    Thanks in advance.

    Trusted

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    wouldn't it be easier to create your form in the designer?

    Project-->Add Windows Form

  3. #3

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Hahahaaa...

    Thanks.paul

    I don't mean that... I know, I have to create multiple forms. It is for a free language learning course. So, there are lot of lessons and exercises. I want each lesson and each exercise has to be open in a new form with the same setting as the first lesson has.

    First lesson has been designed as you said, but other lessons [on different forms] has to opened on clicking of buttons.

    Hope you got it.

    Trusted

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         Dim MyForm As New Form()
    5.         Dim MyPanel As New Panel()
    6.         Dim MyPicBox As New PictureBox()
    7.  
    8.         MyForm.Width = 705
    9.         MyForm.Height = 520
    10.         MyForm.Text = "Lesson # 1"
    11.         'MyForm.BackgroundImage = My.Resources.Background
    12.         MyForm.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
    13.  
    14.         MyPanel.Width = 649
    15.         MyPanel.Height = 373
    16.         MyPanel.Location = New Point(19, 55)
    17.         MyPanel.BackColor = Color.White
    18.  
    19.         MyPicBox.Dock = DockStyle.Fill
    20.         MyPanel.Controls.Add(MyPicBox)
    21.         MyForm.Controls.Add(MyPanel)
    22.  
    23.         MyForm.Show()
    24.  
    25.     End Sub
    26.  
    27. End Class

  5. #5

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Nope!

    Still not working!

    Getting the same result "a big plane box"



    Trusted

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    if you have a standard form that you want to use to display all of your lessons:

    vb Code:
    1. dim frm as new form1 'where form1 is your standard form
    2. frm.show

  7. #7

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Form1 is the main form that shows instructions and introduction to the course. When a user press the learn button or "lesson 1" button, a new form has to be opened up with a new panel at 19,55 and a new picturebox inside that panel.

    When a user finish learning the first lesson, he/she has to click on exercise button, then a new form will open again with the same properties, a new panel 19, 55 and a new picturebox inside it.

    This is how it works.

    I am trying this way, cause I don't know how to use the same form for so many lessons and exercises. Oops, btw, I don't know this way too :P

    Trusted

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    design the lesson form in the designer, then use the code from post #6 to open a new instance of that form. i'm guessing your lesson information will be in the form of a bitmap that you'll display in the picturebox?

  9. #9

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Correct.paul.YouAreRight

    My lessons are bitmaps that I want to display in pictureboxes.

    I did not follow. How can I get the previously designed form when I use a new instance. As per Post # 6, I guess, it will open a blank form. right?

    Trusted

  10. #10

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Hey, I got it...

    I am sorry, I was making a mistake... This code has to be written under a label and I was writing it under a button... Sorry again.

    But a problem occurs. the picturebox in a new form appear at the left corner of panel. Can I align it at center? How?

    Another problem, an "Out of Memory" exception. How can I handle this. I have 4 GB RAM but just to load a background image I am getting Out of Memory. Please help.

    Trusted.

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    here's an example:
    Attached Files Attached Files

  12. #12
    Member henriqueshb's Avatar
    Join Date
    Jun 2010
    Posts
    59

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Quote Originally Posted by Trusted View Post
    Hey, I got it...

    I am sorry, I was making a mistake... This code has to be written under a label and I was writing it under a button... Sorry again.

    But a problem occurs. the picturebox in a new form appear at the left corner of panel. Can I align it at center? How?

    Another problem, an "Out of Memory" exception. How can I handle this. I have 4 GB RAM but just to load a background image I am getting Out of Memory. Please help.

    Trusted.
    Man, I've faced something like your now.
    take a look here.
    Its my thread, I was trying to always get the same point on the screen even if the screen size changes. I think you can modify it to fit your problem or I'm saying a stupid think!!!
    Well, try it. It's free...
    hehehe
    Did you like?
    Rate it!
    by SHB

  13. #13

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Hey Paul,

    I could not able to open. VB 2010 don't support that format. It is not converting it even after trying.

    Trusted.

  14. #14

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Quote Originally Posted by henriqueshb View Post
    Man, I've faced something like your now.
    take a look here.
    Its my thread, I was trying to always get the same point on the screen even if the screen size changes. I think you can modify it to fit your problem or I'm saying a stupid think!!!
    Well, try it. It's free...
    hehehe
    Hi Henri,

    Thanks for your post. But my problem is not similar to yours...

    But nice to know that you solved your problem. Great!

    Trusted.

  15. #15
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    ok. i upgraded it for you
    Attached Files Attached Files

  16. #16

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Hey Paul,

    It is working perfectly, but the only problem is, I cannot use only 1 button for all the lessons. When a user finish the lesson 1 he is asked to complete the exercise [i.e., an exam for lesson 1] IF he pass the exam or get the score upto 90-100% then a button will appear on his first lesson result page that will lead him to the second lesson.

    This is how it is...

    Trusted.

  17. #17
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    ok. you know how to use instances of forms. you could put a next button on your form + set visible = false, then make it visible when the user passes the exam.

    do as much as you can, then post here when you have a specific problem

  18. #18

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Thanks for all your help Paul.

    I don't know how to use instances of form, but I will try, and get back to you if I get stuck.

    Can you please help me with a new label on a new form?

    I tried as:

    Code:
    dim mylabel as new label
    
    mylabel.text = "x"
    mylabel.forecolor = color.black
    mylabel.location = new point (665, 12)
    But NO label appears on the new form. What could be the problem?

    Trusted

  19. #19
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    add this:

    vb Code:
    1. me.controls.add(mylabel)

  20. #20

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Oh yes,

    I did that... thanks a million

    I wrote myform.controls.add(mylabel)

    and it worked.

    Thanks again

    Trusted

    "Is it possible to make the new form draggable ?"

  21. #21
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    it will be draggable by default if you use a formborderstyle that has a border + titlebar.

    for borderless forms you can use api functions:

    vb Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Public Class Form1
    4.  
    5.     Dim moveDown As Boolean = False
    6.  
    7.     Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    8.         moveDown = True
    9.     End Sub
    10.  
    11.     Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    12.         If moveDown Then
    13.             ReleaseCapture()
    14.             SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)
    15.         End If
    16.     End Sub
    17.  
    18.     Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
    19.         moveDown = False
    20.     End Sub
    21.  
    22. #Region " Functions and Constants "
    23.  
    24.     <DllImport("user32.dll")> _
    25.     Public Shared Function ReleaseCapture() As Boolean
    26.     End Function
    27.  
    28.     <DllImport("user32.dll")> _
    29.     Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    30.     End Function
    31.  
    32.     Private Const WM_NCLBUTTONDOWN As Integer = &HA1
    33.     Private Const HTBORDER As Integer = 18
    34.     Private Const HTBOTTOM As Integer = 15
    35.     Private Const HTBOTTOMLEFT As Integer = 16
    36.     Private Const HTBOTTOMRIGHT As Integer = 17
    37.     Private Const HTCAPTION As Integer = 2
    38.     Private Const HTLEFT As Integer = 10
    39.     Private Const HTRIGHT As Integer = 11
    40.     Private Const HTTOP As Integer = 12
    41.     Private Const HTTOPLEFT As Integer = 13
    42.     Private Const HTTOPRIGHT As Integer = 14
    43.  
    44. #End Region
    45.  
    46. End Class

  22. #22

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    I already have draggable code in my main form.

    I could not able to do it for my new form.

    BTW, what is "region" part, I don't understand anything in it. And I don't have it on my main form, but it is still draggable.

    Trusted.

    Reputation.added(to.Paul)
    Last edited by Trusted; Jun 26th, 2010 at 06:27 PM.

  23. #23
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Quote Originally Posted by .paul. View Post
    it will be draggable by default if you use a formborderstyle that has a border + titlebar.
    the code in the region is API function declarations + constants used by those API functions

  24. #24

    Thread Starter
    Hyperactive Member Trusted's Avatar
    Join Date
    Jun 2010
    Location
    Don't Know, Cause, I am a Newbie :P
    Posts
    269

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    Oh ok...

    Thanks again Paul.

    Hey, how can I say this thread is resolved?

    Sorry for asking a bunch of questions.

    Have a good day!

    Trusted

  25. #25
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [:: A new Form with a new Panel and a new Picturebox on it ::]

    use - Mark thread RESOLVED in the Thread Tools menu above + to the right of the 1st post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width