-
[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
-
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
-
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
-
Re: [:: A new Form with a new Panel and a new Picturebox on it ::]
try this:
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyForm As New Form()
Dim MyPanel As New Panel()
Dim MyPicBox As New PictureBox()
MyForm.Width = 705
MyForm.Height = 520
MyForm.Text = "Lesson # 1"
'MyForm.BackgroundImage = My.Resources.Background
MyForm.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
MyPanel.Width = 649
MyPanel.Height = 373
MyPanel.Location = New Point(19, 55)
MyPanel.BackColor = Color.White
MyPicBox.Dock = DockStyle.Fill
MyPanel.Controls.Add(MyPicBox)
MyForm.Controls.Add(MyPanel)
MyForm.Show()
End Sub
End Class
-
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
-
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:
dim frm as new form1 'where form1 is your standard form
frm.show
-
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
-
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?
-
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
-
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.
-
1 Attachment(s)
Re: [:: A new Form with a new Panel and a new Picturebox on it ::]
-
Re: [:: A new Form with a new Panel and a new Picturebox on it ::]
Quote:
Originally Posted by
Trusted
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
-
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.
-
Re: [:: A new Form with a new Panel and a new Picturebox on it ::]
Quote:
Originally Posted by
henriqueshb
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! :thumb:
Trusted.
-
1 Attachment(s)
Re: [:: A new Form with a new Panel and a new Picturebox on it ::]
ok. i upgraded it for you
-
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.
-
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
-
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
-
Re: [:: A new Form with a new Panel and a new Picturebox on it ::]
-
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 ?"
-
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:
Imports System.Runtime.InteropServices
Public Class Form1
Dim moveDown As Boolean = False
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
moveDown = True
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If moveDown Then
ReleaseCapture()
SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
moveDown = False
End Sub
#Region " Functions and Constants "
<DllImport("user32.dll")> _
Public Shared Function ReleaseCapture() As Boolean
End Function
<DllImport("user32.dll")> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Private Const WM_NCLBUTTONDOWN As Integer = &HA1
Private Const HTBORDER As Integer = 18
Private Const HTBOTTOM As Integer = 15
Private Const HTBOTTOMLEFT As Integer = 16
Private Const HTBOTTOMRIGHT As Integer = 17
Private Const HTCAPTION As Integer = 2
Private Const HTLEFT As Integer = 10
Private Const HTRIGHT As Integer = 11
Private Const HTTOP As Integer = 12
Private Const HTTOPLEFT As Integer = 13
Private Const HTTOPRIGHT As Integer = 14
#End Region
End Class
-
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)
-
Re: [:: A new Form with a new Panel and a new Picturebox on it ::]
Quote:
Originally Posted by
.paul.
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
-
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
-
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