Where do I find those WinForms controls? - winforms

I am looking for a WinForms control that, I believe, in the days of VB 6.0 (I can't remember if it was VB 6 or .NET 1.1) used to be called the ButtonImage or ImageButton or some such. Whatever it was called is not important.
What it used to look like and behave like is the important thing.
If you open Control Panel -> Add Remove Programs in Windows XP, the buttons on the left Change or Remove Programs, Add New Programs, etc. use tat control. I want a control that looks like that. It's a button with an image but stays pressed when it is selected.
Secondly, I am looking for a splitter. I see one in the Toolbox in Windows Forms apps, but when I try to change its size at runtime, it won't.
Do I have to use a SplitterContainer first or something?

You may make use of RadioButton control or CheckBox control.
Add the control and change the Appearance property of RadioButton to Button. Add a BackgroundImage to that.

Unfortunately this control doesn't exist in Windows Forms. You will probably find one in commercial control libraries, look for Outlook-type menus.
For the splitter, you have to use a SplitterContainer, which is two panels separated by a splitter. Then you add your controls on both splitters and will be able to move the splitter and everything.

For starters you can make the button use an image by tweaking the properties like so
Button1.Text = ""
Button1.Size = New Size(100, 100)
Button1.TextImageRelation = TextImageRelation.ImageAboveText
Button1.Image = My.Resources.Image1
That would make the button look like this
You could also swap out the image every time the user clicks with the buttons click event.
Make sure to replace image1 and image2 with the real images.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Image = image1 Then
Button1.Image = image2
Else
Button1.Image = image1
End If
End Sub
You if you want the image to border and hover to be different try messing around with the button.FlatStyle = flat and the FlatAppearance property's.

Related

A combination of winforms' controls as a prefab?

In our winforms application we often have a situation where the same panel is used in different forms. Right now I simply copy the code and the designer elements from form to form but that is obviously a terrible practice.
So I thought of making a class that could be easily added to a different form as a "component". The only problem is to be able to prototype and maintain this panel in the visual designer in such a way that if I want to change the panel's appearance in the future it gets changed for every class instance I created.
For instance I have a panel that provides search functionality:
Alongside with the code for click/textChanged events. I want to encapsulate it in a class, which I would be able to instantiate and initialize in any form's constructor to instantly add these controls (alongside events) into that form. Now it is not necessary for me to see the controls in the designer of the recepient form, however, I need to be able to see them in the designer somewhere in order to modify them if I would ever require that.
And if I do modify the appearance somehow (for instance add an extra button) these controls instantly change across the entire project, everywhere I instantiated the class.
I do know that all this can easily be done just creating a new form and encapsulating everything in it, I just wonder if it can be done for a group of controls instead.
You just described the perfect use of a User Control. It's easy to use and direct.
First Add a user COntrol to the project:
Then add the desired controls on the user control:
Build the project and you will see the UserControl on the toolbox:
Add them to the form as a standard control:
If you change the code for the user control (in this case adding a button click handler) uit will affect all the intances of that user control:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = "Button Clicked"
End Sub
Note: If you have the Control in another project on the same solution, make sure you build that project too if you make any change.

On Click (text box,) Open Window

I am trying to build a basic front-end to link information together that would be accessible by clicking a text box (or a button) on the front page of the GUI. Basically, I have a number of text boxes for the different "functions" I want to show information on.
How do I make it so that on click, that box will open up a new window that I've already designeD? Within the solution (WPApplication,) I have all of the .xaml's set up (that are the seperate windows) in the solution already- I just want to call the on-click to open them. I figured it'd just be Show('Window Name') after private/as/handles, but it gives me an expression. Here's what I have:
Private Sub PO_info_MouseDown(Sendar As Object, e As MouseButtonEventArgs) Handles PO_Info.Mousedown
Show('PO Information')
End Sub
End Class
To flesh out my comment, the new window objects that you created are classes, you need to create an instance of the class before the Show Method will work. Lets assume that your PO Information forms class is POInfo you would need to do something like this.
POInfo POInformation = new POInfo;
POinformation.Show(); //This is where your show method is
Since your code looks like vb.net it would look like this in VB
Dim POInformation as New PoInfo
POInformation.Show()

Blacklight Expander problem while expanding programmatically

I am doing a silverlight project in Silverlight 4 and I included the BlackLight project in my project so that I could use their new controls, especialy the dockpanel and the autoexpander, which is causing me at the moment some little problems.
What I would like to do is to have several auto-expander that will expand or collapsed when I click on button. In my case more specifically, each auto-expander have a set of parameter to fill, which in turn will fill the other expander and the current one would collaps and the just filled one would expand.
The idea is simple, yet when I use a button which is on one of my expander, it only works once... It would expand/collapse the first time, then after that, nothing. I trace the code and it seems to go through just fine, but the property value won't change
Here is my code
Private Sub BtnExpand_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnExpand.Click
ClientExpander.IsExpanded = False
ProjetExpander.IsExpanded = True
End Sub
Could it be a known bug, or must I reset some flags to make it work?
Edit : Forgot to mention, if it makes any difference, but the IsExpanded property seems to be a dependancy property.
Thanks.

Loosely couple a modal dialog - is this possible?

I have a winforms custom UI control library which contains a control for displaying modal dialogs Picture-in-Picture.
This custom control receives as a parameter a pointer to the control which has initiated it's display. So they are tied together. This allows the control to be modally displayed over the window which launched it.
Dim f As New PiPCustomDialog 'this form wraps another form PictureInPicture style
f.FormToLoad = New PrintOptions() 'this is the form the user will interact with
f.Owner = Me 'used to determine the size of PiPCustomDialog
Dim dr As DialogResult = f.ShowDialog(Me) 'shows PiPCustonDialog coating, f's OnLoad event initiates display of FormToLoad centered within.
The fact that this control requires f.Owner to be set is what is stinky. User32.dll has a function GetActiveWindow() which would maybe allow the control to be more self-sufficient.
Anyone out there who would like to teach this old dog a new trick? I want to learn a better way.
I'll use this solution for now:
Remove any validation that requires
owner to be set before showing the
form modally.
if owner isn't set inside the class that is transparent cover
(first form) - do a system call into
GetActiveWindow to get owner so the size of the window can be set.

Displaying controls on an alpha-blended form

I tried the Visual C# Kicks code for an alpha-blended form. This works (as soon as I remove the TransparencyKey property); that is, I can use the W3C's PNG alpha test image and see other windows underneath, but makes all controls on the form invisible. Presumably, they simply aren't painted, as OnPaint is overridden. I tried calling the superclass's OnPaint:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
UpdateFormDisplay()
MyBase.OnPaint(e)
End Sub
, but this didn't change anything. (Calling MyBase.OnPaint first doesn't make any difference either.)
Unfortunately most articles about alpha-blended forms focus on pure splash screens without any controls on them — but we need a panel which first shows sign-in fields, then a progress bar.
The controls, by the way, do not need transparency; it's only on the outer edges that the PNG's transparency truly matters. So faking this by adding another form on top of this all (with the two always moving in tandem) might suffice, but I'd prefer a smoother solution.
Try putting this in your form ctor after InitializeComponents();
base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);

Resources