How to set GridLayout for WinForms control i.e. Panel - c#

How can one set GridLayout known from Java or Wpf in WinForms control? Is it available by default or does it require writing some code (custom LayoutEngine implementation)?

Yes, it is available by default. If you are using Visual Studio, just drag it from toolbox to your form and set properties.

As far as I know Windows Forms work totally different from Java and WPF forms. One of thier differences is that there's no layout for windows forms whatsoever, instead there's this ability that you can place a control whenever you would like using its location property.

Related

Why are Aero visual style animations missing on my Windows Forms buttons?

I wrote a C# Windows Forms program with some buttons on Windows 7. The buttons use the built-in Aero style, including hover and pressed states, but they do not smoothly fade between the different states like buttons do in other programs. Instead, they just immediately transition to the new state. I want them to animate with the default Aero transitions.
What I've tried
Ensured the animations were appearing in other programs, like the Run, Open, and Save dialogs provided by the OS.
Ensured "Animate elements and controls inside windows" was enabled in System Properties > Performance Options.
Switched my OS visual style between Windows 7 Basic, Windows 7 Aero, and a custom visual style.
Added an application manifest which specified a dependentAssembly on Microsoft.Windows.Common-Controls.
Ensured I was calling Application.EnableVisualStyles() before showing any forms.
Ensured Application.RenderWithVisualStyles was true.
Read Rendering Controls with Visual Styles to see if I was missing anything.
Thanks to Matheus Pratta's (for some reason) YouTube video, I learned that I have to individually set the property ButtonBase.FlatStyle = FlatStyle.System on every one of my button controls that I don't want to have broken animations.
To fix all controls in a form, you can multi-select them in the Visual Studio Forms Designer and use the Properties panel.
Alternately, you can use a loop to fix all controls in a form procedurally.
InitializeComponent();
foreach (Control control in Controls)
{
if (control is ButtonBase buttonControl)
{
buttonControl.FlatStyle = FlatStyle.System;
}
}
It seems highly ridiculous that you would have to do this just to unbreak animations. My application is simple and has one form, but if you have many forms, you would want a way to apply this fix application-wide. What if your class inheritance structure does not allow you to add this fix to a superclass, possibly because your form classes are inheriting from a variety of unchangeable (possibly third-party) superclasses? You could extract a helper method, but what about when you create a new form class and forget to call the helper method?
There should be a way to opt in to FlatStyle.System as an application-wide setting, and it could even be enabled by default, because every other program in the OS uses these animations on their buttons.

How to make a custom control and component for Metro development?

I'd like to get ahead of the pack and start making some custom C# controls and components for Metro (Win8), but I can't find any documentation or blog posts on how to start, or even if it's possible right now.
Are metro controls just WPF controls? I'm not yet a WPF developer; creating a custom user control looks straightforward, but that project type doesn't exist in the Windows 8 developer preview. So, are WPF custom user controls (VS2010) the project type I should use for creating my Metro controls? Beyond that, I can't find any documentation on how to create a component for use in WPF/Metro; can you create one, or would it just be a custom user control that isn't visible? (I was hoping for some type of component container like the one winforms use; are components for Metro now only class libraries, and don't include designer support anymore?)
It's ... very difficult right now. There's no way to override OnRender or the like for a control, ie to create code to render a control with a custom appearance. However, you can create a custom template. Anything you can do in the template is legal, and that's how you have to approach custom controls.
One other option is to generate your UI using either raster (Bitmap) or vector (Windows.UI.Xaml.Shape?) components directly and build up your UI like that. Bleh.
Win8 Metro is a lot like WPF, but it isn't a subset. Similar but very different. Many WPF controls didn't make the transition to Win8 Metro; the same level of rendering control isn't available; and some system features (like advanced font rendering) aren't there. All this might change in coming releases, but right now it looks like Microsoft is trying to restrain developers from creating custom UI controls.

Creating a color def file or choosing a theme for Windows Mobile 6.5 Application

I developing an application in C# on Windows mobile 6.5 and .NET 3.5 CF. I'm using multiple forms and would like to have a common color scheme that is easily changed by just changing a color definition file or some simple option in VS 2008.
I've looked around and it doesn't seem to be any clear solution. I've tried digging down to where the colors are defined to see it I could add my own that would be a global variable, or even in the designer files, but there is not mention of color, the only way I can change the color is in the properties window.
A simple way to do this is to use Form inheritance. Create a template form (named "TemplateForm.frm" or whatever), color/style is as you wish, then add one (invisible) instance of each type of control (a Button, a Checkbox, a Label etc.) that you're using on all of your other forms.
Then edit your existing forms so that they inherit from TemplateForm (instead of inheriting from Form). Add a method to TemplateForm's Load event that iterates through all the controls on the form (this needs to be recursive, of course) and styles each one (font, colors etc.) to match the corresponding (invisible template) control of that type on the parent form.
An other approach, probably not better, is to modify the system colors in the registry in [HKEY_LOCAL_MACHINE\System\GWE] "SysColor". I've used it, but I'm not a fan as it is sometime hard to get a good set of colors that work, and it changes it everywhere in the system. #MusiGenesis appoach affords you finer control.
see Customizing System Colors

ActiveX controls are disabled during design time in WPF application

I am developing WPF windows application using VS 2008 and .NET 3.5. I am trying to use Mozilla Web browser activeX control in my application. I have added it to my tool box. The control is visible in tool box but it is disabled state. I am not able to use it during design time. This does not happen with normal Windows Form Application, I am able to use same control during design time.
Can anybody help me to understand this strange behavior?
Thanks,
Omkar
WPF doesn't directly support ActiveX controls. You'll need Winforms to give it a hospitable runtime environment and leverage the auto-generated AxHost wrapper. The WindowsFormHost control is available to embed winforms controls in a WPF window. The walkthrough that shows the technique is available here.

Is there a way to prevent WinForms controls in a WPF window from being unstyled?

I have some WinForms controls that I need to use in a WPF window. I'm able to get the controls to show up just fine and everything works as I would expect, but I'm experiencing one issue: all the WinForms controls are unstyled.
I'd like for the WinForms controls to at least use the default OS style (like I would see in a WinForms application). Is there any way to control this, or do I have to live with the controls the way they are?
The WinForms controls can't use the WPF styles, because Windows Forms doesn't understand the WPF styling and templating system.
To get them to use the "OS style" (the OS visual theme), try calling System.Windows.Forms.Application.EnableVisualStyles in your Main method. (I thought WPF handled this automatically, but I guess that's not what you're seeing.) This must be called before any controls get created!

Categories

Resources