I'm using vb.net to make a screen saver.
I want my label where the text shows to always be centered no matter what screen size it is.
is there a way to get the screen resolution of the current monitor?
if i can get that then i can calculate the middle and set my label there.
Stretch the label to the whole width of the form and dock/anchor to left and right side within the label parameters. This will center your label whatever the size of the form.
Related
I am trying to create a Ludo game using Windows Forms.
I have set the background to be the image of a ludo board, where both the image and the window have the same size (960x960). I cannot use the image stretch feature, as it will mess with the button positions on my Form.
The Form has the bottom and the right side of the background image trimmed off, even though the Form matches the size of the background image.
The Size of the form is the outer dimensions. You should set the ClientSize of your form to the Size of the Image, which you can do in code. That way, the image and form will look correct no matter what window chrome is or isn't present.
I am doing a WinForms program which should have a fully responsive design in a full screen.
I get an approach which works more or less well. It consists into calculate a ratio between display screen and original form size.
Then I apply this ratio to the width, left, height, top properties of each control inside the form.
My doubt is about to use a native way for doing this, since, using anchors, the controls keep their same distances with parent control borders, but I doesn't do proportionally, for instance:
Form with 100x100
Button 20x20 located in (10,10)
If I resized the form to 200x200 (multiply by 2), the best approach I can do in design view is keeping the four anchors to the button, so button size will be 120x120 at the same position (10,10), while what I need is a button with size 40x40, at position (20,20), since form size was multiply by 2.
Is it possible with winforms native operations in design view? (Avoiding to make calculations)
Yes it is possible.
Using the Property Dock = Fill you can ask for a component to take all the room in its container.
Now using a TableLayoutPanel, you can define cells to put your components in. And giving cell a percentage size, you can make sure the sizes will change when the form is resized...
Here are more information on these things :
Dock Property
TableLayoutPanel Class
TableLayoutPanel Tutorial
I am trying to implement like word cloud in my app.
The image shown is like word cloud with left alignment.
What I did was, for placing the buttons I am checking whether the width of the text is greater than total width of the screen, if it is greater place the button in next row i.e increment the y position, if it is not just place the buttons. Everything is working fine. But what I want now is , i want to move the buttons alignment, like, I want to start the first button from center of the screen. Please help me to do this...
I am using Visual Basic in Visual Studio 10 .I have a windows form and I have to display a world map(a jpeg displayed in picturebox ) with radio buttons over each of the country . The problem is while resizing the window the radio buttons get dislocated. One way to fix this is calculating the ratio of
Scree.width/(initial x-coordinate of radio box)
and similarly
Screen.height/(initial y-coordinate of radio box)
and using this to generate the new x and y coordinates after resizing but as the number of countries are too large this is very tedious and for smaller countries the difference in the initial coordinates is not much and due to precision loss in higher resolution the radio box are overlapping. Is there a workaround for this. Also the method described isn't working after adding zoom as the portion of image displayed on screen changes and as a followup I would like to ask how can I add sliding functionality to image ( like after clicking the mousedown and moving the pointer should move the image keeping the radio boxes over the respective countries, Is using scroll bars better for this purpose? )
Replace your PictureBox with a Panel.
With the PANEL and your IMAGE set:
PANEL.BackgroundImage = IMAGE
PANEL.BackgroundImageLayout = ImageLayout.None
PANEL.AutoScroll = True
PANEL.AutoScrollMinSize = IMAGE.Size
At last, add all RadioButtons to the PANEL.
I have designed a form in VB.NET. At design time I have placed two buttons on it.
When I run it, the form size looks smaller and the buttons I have placed at the bottom are not visible. Also the alignment of the text and picture box is also different from what I set at design time.
Computer at which I am running the form is using a different resolution.
change the properties (F4) of the buttons: in ANCHOR put Bottom, Right
your buttons will be tied to the bottom and the right of the screen, instead of to the top, left, which is the default.
Grab the screen size at runtime with
Dim screen as System.Windows.Forms.Screen = System.Windows.Forms.Screen.PrimaryScreen
and using a scale factor depending on the current size (in design), scale the window to match. Check the coordinates of the buttons by hand to make sure they are not outside of the visible portion of the window.
You may not have to leave this feature in if you can debug it to the point that you know the exact resolution that you need.