how to set fix background image for windows form c#? - c#

I have a windows form application.I set background image for this form and BackgroundImagelayout property is Stretch.When I put a button on the specified place on image and run this app,place moving and commix my design
What should I do? Help me please

This should work for you
Define the size of the form
make the form not resizable
make the image same size of the form
fix the background, not stretch
set the anchor property of objects to top left

If you are trying to make a layout that can size, you will need to break up your graphical elements into multiple parts, and then use layout controls with parts of the background image that can reposition as the form resizes.
For example, your form can have a tiled pattern, stretched gradient, or whatever you may have. Then, you can have a TableLayoutPanel that contains evenly spaced buttons and fields. The panel can have a background image of its own. The same goes for the other layout containers. You can nest the containers if the design requires it.
Then, you can set the various anchors and docking to keep the design uniform.

Related

C# form adjusting screen resolution without sizable

I have created a c# windows forms program with a Form which includes a Diagram, an image and Buttons. When I open the program the Form to big for the computer screen this is because the screen resolution is to big or to small.
How can I make the Form exactly right for each screen resolution type whiteout using sizable?
The problem is because you define (Pixel) sizes for your controls and therefore also your Form.
You can put your space consuming controls (diagrams, images) into Panels and then set the Dock property appropriately (on the controls and/or the panels) so that they scale out to their maximum size. This way you can reduce the size of the Form and because you define ratios rather than pixel numbers the controls/labels will expand as needed.
Depending on how you want it to look like you will have to play with different configurations (one or two controls in one label and then setting dock either to fill or left/right/top/bottom). There's also the SplitContainer control to help you achieve certain design goals.
Additionally, if you always want the perfectly scaled window, open the form in Maximised mode:
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

Make WPF Usercontrol resize entirely

In my application I have one frame resource and lots of icons resources. All of them are Path types. I would like to make a Usercontrol using the frame and one icon. The image bellow shows it better than any words:
I tried to make two grids, one overlapping another. On the icon grid I set the margins so the icon could fit correctly. But when I use this control in another place and resize it WPF tries to keep the margin values I set if it's too small the icon disappears from the frame. Is there any way to achieve this in WPF or do I have to duplicate all my icon paths to include the frame?
You can wrap your UserControl content inside a ViewBox. This will allow your content to scale correctly when the control is resized.

Windows Forms C# Panel should not have white background, and panel should be only image

I have a windows forms, i have placed an image on it, and the image is not rectangular, so white space lefts with it, because windows form is either square or rectangular, but image is not, i want panel should be only image, rest of the space should not be visible, i am attaching an image to describe further.
Thanks
Atif
as I understand it you want your form to be invisible?
that isn't supported well in winforms and you should consider moving to WPF.
however theres this example:
http://www.blackbeltcoder.com/Articles/winforms/non-rectangular-splash-screen-for-winforms
create a splash screen as the writer advices.
I think you have set form properties [BackgroundImageLayout:stretch] or
you have to change image size(width,height) same as form size(width,height)
Read the ImageSize before applying to the form.
Resize the form with the image size.
If you can set the ControlBox property of the Form, you can even hide the Close, Maximize and Minimize buttons from the right top corner.
So you mean to stretch your image to the window frame? Just dock the picturebox to full form size. There is an option called Dock in parent container. Use that
You need to set the BackgroundImageLayout property to ImageLayout.Stretch, ImageLayout.Zoom or ImageLayout.Tile depending on how you want the image to fill the Form.
Put the image on the form directly by setting the following properties:
Form1.BackgroundImage = MyBackgroundImage
Form1.BackgroundImageLayout = Stretch

Dock, Anchor and Fluid layouts in Windows Forms Applications

So, I've been asked to redesign an old application I wrote a few years ago.
Basically, nothing much needs to be changed, except that the Customer wants it to be more fluid, and that it must be fullscreen (no visible "window") I.e. no Titlebar, just a Borderless fullscreen Window.
What is the best way to make sure everything stays fluid, I mean how can we make sure everything appears where it should, 'cause you know, different resolutions, monitor sizes etc?
This is easy in web pages/css, but this is not something I've done before. Most of the Controls will be created programatically at runtime, based on what action was performed, etc. How would I accomplish such a layout? Basically I want to be able to lay it all out full screen, without knowing how large their monitor is, or what resolution they're using.
Your certainly correct in trying to design your form using a fluid layout that responds to the size of the available space and size of the form font. To do that you want to use the following controls and control properties.
1, TableLayoutPanel will split an area into a set of rows and columns and allow you to position your child controls within individual cells of that table layout. This responds to a change in the form width and height.
2, FlowLayoutPanel will position your child controls from left to right and automatically move to a new row when you run out of space. This is great for a fluid design as it will adjust the layout depending on the available space.
3, Control.Anchor property allows a child control to alter position and size based on the size of the form client area. So you make your control always be a fixed offset from the right or bottom edges.
4, Control.Dock property will position a child control against an edge and the opposite size will automatically be defined by the containing form.
You could put Your controls into tableLayout, and set the Dock property to fill.

Resizing componenets on a c# form

typically in java if you have a layout manager of somesort, when you resize the page then the components in that panel will resize accordingly. I think my app is missing some sort of layout manager to control resizing as at the moment everything is just static
Is there a way to make it resize on the changing of the form size? say the user makes the page bigger, then the componenets adjust and so on.
Thanks
.NET has layout managers as well.
Personally, I prefer the TableLayoutPanel for my WinForms apps.
Once you layout the Table (using a combination of static/dynamic sized rows/columns) you add your child controls to the table cells. Once you add your controls, you can dock or anchor the controls to the cell so that they are automatically adjusted when the window is re-sized.
Two main options:
Anchoring. Set your control to "anchor" to the sides of your form. This means that if the form resizes, the control will stay a constant distance from that side. So, if you anchor Top, Left and Right, then your control will stay in the same position, but resize horizontally with the width of the form. Play with it. It'll be obvious.
Docking. Set your control to "dock" to a side of the form, or the center. This is usually done with containers, and it will make the widget take up that entire portion of the form no matter how large it gets.
In Windows Forms you make use of the Control.Anchor property, which will cause the control to adjust accordingly when the window resizes.
To do this with windows forms you use the Anchor and Dock properties of the control
See this for a guide on how to use them

Categories