CONTROL POSITION AFTER FORM RESIZE

Hi All,

I have a form with group box.
At load I resize the form to screen size.

In the groupbox there are controls like below :

InvoicNo : xxxxxxx     Invoice Date : xxxxxxxxx    Due Date : xxxxxxxx

xxxx of InvoiceDate and DueDate is datetimepicker

How could I move controls at middle (Invoice Date : xxxxxx) still in the middle and Due Date to the right side after the formis resize?

Thank you.

 

LVL 1
emi_sastraAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
 
khan_webguruCommented:
Get Idea from this:

 
Imports System.Runtime.InteropServices
Public Class Form1

    <DllImport("user32.dll")> _
    Public Shared Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True)> _
    Public Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInt32) As Boolean
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function FindWindowEx(ByVal hWnd As IntPtr, ByVal hWndChild As IntPtr, ByVal lpszClassName As String, ByVal lpszWindow As String) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Int32) As Int32
    End Function
    Public Shared ReadOnly SWP_NOSIZE As UInt32 = Convert.ToUInt32(&H1)    'Ignore Width and Height

    Private m_hWndStart As IntPtr
    Private m_hWndTaskBar As IntPtr

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        m_hWndTaskBar = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", vbNullString)
        m_hWndStart = FindWindowEx(m_hWndTaskBar, IntPtr.Zero, "BUTTON", vbNullString)

        'Move the Start Menu to 100, 0
        SetWindowPos(m_hWndStart, IntPtr.Zero, 100, 0, 0, 0, SWP_NOSIZE)
    End Sub

End Class

Open in new window


Hope this will help you

reference:  http://www.daniweb.com/software-development/vbnet/threads/247421

Useful links

http://www.blogsdna.com/5018/move-windows-xp-start-button-system-tray-on-taskbar.htm

http://msdn.microsoft.com/en-us/library/ms633545%28VS.85%29.aspx

http://bytes.com/topic/net/answers/852856-control-resize-positioning-run-time-vb-net
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
emi_sastraAuthor Commented:
Hi khan_webguru,

Maybe I missed describe what I want.

I mean after the form is resized base on screen size, all the controls where are in the middle of the groupbox still stay at the middle.

Usually using anchor or whatever.

BTW, where is the link solve the problem?

Thank you.
0
 
Avinash DesaiSr Software EngineerCommented:
Check out for anchor and autosize property of the controls it helps you to resize according to form size .

Regards
Avinash Desai
0
 
emi_sastraAuthor Commented:
Hi Avinash_Desai,

I know about anchor, but I need a guide how to do it for questions I ask.

Thank you.
0
 
Avinash DesaiSr Software EngineerCommented:
0
 
khan_webguruCommented:
Hi,

Please look here for Anchoring and Docking Controls in VB.NET

http://www.startvbdotnet.com/forms/form4.aspx

Thanks,

0
 
emi_sastraAuthor Commented:
Hi Idle_Mind,

I have tried it, use 3 columns, with panel control each, since I want to store more controls inside the column, thus panel is the most suitable.
isn't it ?

Colum1                      Column2                            Column 3
Panel1                       Panel2                               Panel3
InvoicNo : xxxxxxx     Invoice Date : xxxxxxxxx    Due Date : xxxxxxxx

The problem is panel3 which contains Due Date : xxxxxxxx not appeared right justified.

How to solve this ?

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Sure...if you need even more control you can nest TableLayoutPanels inside each other.  For instance, Panel3 could be replaced with a TableLayoutPanel of Two Columns and One Row.  Put the "Due Date:" in a Label in Column 1 and Left Justifty (TextAlign Property) it, with the other part in a separate Label in Column 2 and Right Justify it.  (or just use one Label and Right Justify the whole thing).
0
 
emi_sastraAuthor Commented:
I use 1 TableLayoutPanel with 3 columns.
Do you see the problem what I meant ?

The problem is at panel3 at column3, it is not shown at right side.

Due Date supposed to be inside panel3 at column3.

Thank you
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Set Panel3 Dock to Fill.  Place the Label inside Panel3 and either Dock it to the Right, or set it to Dock Fill and TextAlign Right.
0
 
emi_sastraAuthor Commented:
Sorry, just back.

Still not working.

Panel3 has 2 controls, label and datetimepicker.

Thank you.
0
 
emi_sastraAuthor Commented:
Colum1                      Column2                            Column 3
Panel1                       Panel2                               Panel3
InvoicNo : xxxxxxx     Invoice Date : xxxxxxxxx    Due Date : xxxxxxxx

Also Column2 not shown at the middle of the form ?

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here's a TableLayoutPanel inside a GroupBox with Dock set to Fill.  It has SIX columns.  Column numbers 1, 3 and 5 are set to Absolute (80 pixels) with column numbers 2, 4 and 6 set to the same Percent (50%).  The Labels in columns 1, 2, 3 and 5 are set to AutoSize False, Dock Fill, and TextAlign Left Middle.  The DateTimePickers in columns 4 and 6 are set to Anchor Left and Right.
 TableLayoutPanel Columns Idle-Mind-439970.flv

Is that close to what you're trying to do?
0
 
emi_sastraAuthor Commented:
Colum1                      Column2                            Column 3
Panel1                       Panel2                               Panel3
InvoicNo : xxxxxxx     Invoice Date : xxxxxxxxx    Due Date : xxxxxxxx
label1      txt1            label2             dtp1             label3        dtp2

I don't want those controls (label, textbox and datetimepicker) resize along with form resize.
I just want the resize the space among the columns increased / decreased when form resize.


Colum1                      Column2                            Column 3
Panel1                       Panel2                               Panel3
InvoicNo : xxxxxxx     Invoice Date : xxxxxxxxx    Due Date : xxxxxxxx
label1      txt1            label2             dtp1             label3        dtp2

To

Colum1                                                               Column2                                                                        Column 3
Panel1                                                                Panel2                                                                           Panel3
InvoicNo : xxxxxxx                                              Invoice Date : xxxxxxxxx                                                Due Date : xxxxxxxx
label1      txt1                                                      label2             dtp1                                                        label3        dtp2

Thank you.
0
 
CodeCruiserCommented:
Have you tried anchoring left controls to the top left and right controls to the top right?
0
 
emi_sastraAuthor Commented:
Column1  absolute 300 pixel
Column2  percent 100
Column3  autosize

pnlLeft anchor top, left   dock fill
pnlmiddle anchor top, left, right   dock fill
pnlright anchor top, left  dock fill

What's wrong ?

Thank you.

0
 
CodeCruiserCommented:
On a new form, just try the controls without any panels and layout tables and set the anchors of controls.
0
 
emi_sastraAuthor Commented:
In that case I need 6 columns ?

It is not flexible, since sometimes we need 3 controls at one column, but not for all columns.

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"I don't want those controls (label, textbox and datetimepicker) resize along with form resize.
I just want the resize the space among the columns increased / decreased when form resize."

Okay...so you need three columns with all them set to the same percent value to make them evenly divide across the form.  Now place a Panel in each columns and set the Dock to Fill on it.  Place the Controls in the Panel and set only the Left Anchor to keep them left justified.
0
 
emi_sastraAuthor Commented:
It does not work.

Let's say column 1, 2 and 3 has different with since the controls inside is different.
One have 2 controls, others have 3.

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
SHOW me with a screenshot what it is doing that you don't want...annotate that puppy with how you want it to align.
0
 
emi_sastraAuthor Commented:
Please see the screen shot.

Thank you.
RESIZE-FORM.PNG
0
 
emi_sastraAuthor Commented:
Column1 has 2 controls
Column2 has 3 controls
Column3 has 2 controls

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
...and you set the SizeType of all the three columns to Percent and made them all the same value?

Is the TableLayoutPanel itself either?
(1) Stretched all the way across the top of the form with the Left and Right Anchor properties set?
(2) Docked to the Top?
0
 
emi_sastraAuthor Commented:
I have set it to 33.33 percent.

Yes, it works, but column3 should be autosized to make it right adjustment.

If the panel set to top, left and right then the dock fill will be set by VB to none.

The TableLayoutPanel should be set to top, left and right, this is the main point why the screen shot happened.

Thank you very much for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.