What component should I use to display enabled/disabled state? [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have been wondering what component I should use to display state of enabled/disabled behaviours in WinForms.
For example I have function that returns state of 2 different processes.
And I want to display like green and red color on GUI, so that user could easily know which process has wich state.
In Java I have used ProgressBar, like setting it to 100 and 0, so it represents the state of that process. But as for now, I have moved to C#, so I would like to know what components you use for this purpose, maybe there is something better to use.

Any component with a background color property will do. I suggest you use Panel and switch the background color according to your state.

You didn't specify the technology, but CheckBox is one option in both WinForms and WPF. Plus you can use Label too (with BackColor / Background properties). Finally if you want to go fancy, you can use animations in WPF.

You could either use a Panel and change its background color or (more intuitively) a read-only CheckBox.
A progress bar is not really a good choice, unless you put it in "marquee" state when something is currently active and hide it when it is not. Otherwise a progress bar is meant to display ... well ... progress.
So this comes down to:
If you want to show that some process is activated/deactivated, for example by some sort of configuration, or simply "not performing a task right now", I'd use either a Panel with a background color or a CheckBox.
If you want to show that some process is currently working (without knowing the exact progress), I'd use a ProgressBack with a "marquee" state (also called "indeterminate").

Related

c# Buttons as toggles [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Hello i am new in C# and need some help
In both groupboxes have buttons they are now like toggle butons, but now can i choose only one button from all.
looking for:
clik one from Groupbox1, one from Groupbox2
clicked buttons will have green background
after press OK show messagebox with button name GB2 + " - " GB1
....................................................
Another question:
Buttons 1-6 can be added as dynamic buttons directly from SQL?
From Sql need have ID and Name
....................................................
Just some hints:
Use a RadioButton with Appearance set to Button.
Check the Remarks of the radio button to find out how to make two groups.
Subscribe to CheckedChanged event and set BackColor according to value in Checked property.
To dynamically insert buttons, take a look into designer.cs file. You can create your own buttons exactly the same way at runtime by doing the same stuff in your own method which you call whenever needed with desired parameters.
For the message box message check the state of all radio buttons and take the name from the box where Checked is true. (Advanced users would filter the Controls property for the desired type and value by using LINQ).
If you have started all of these and have a more concrete question: Ask a new question for one problem. Don't hope to ask one question containing all your questions and get a working example back.

Is this possible to create many form designs and swap between them? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I've just started building up a simple game in Visual Studio using c# (It is my first low difficulty game). As I open it , it shows me a background image and 2 buttons, "Play" and "Instructions."and I want the form to get changed as I click the play button and open a new menu interface , like : " Game Difficulty / Character Appearence "(those 2 are buttons) , with a new background image. When I click one of them, another menu, etc.
Can I create multiple designs( Form1.cs[Design1/2/3]) for my from and swap between them ? If not, then how can I do something similar ?
In my opinion, the easiest way would be to make each menu a "User Control" that is the size of the main form, and then you can add a user control for whichever menu you want to show up as you go along.
For example, in the solution explorer I would create a folder and name it "Menus". Then I would create a new "User Control" in there. Copy the Width and Height of the form it will be placed on and apply that to the new control. Then you can add in all the buttons and images you like. Once you're finished, in your main form, you can add the "main-menu" control you made in the designer. For any submenus you want, create user controls for them too. Then, if you want a submenu to show up, capture a click event for the button you want and programmatically add it to the parent form using FindForm().
Pretend that DifficultyScreenControl is the screen that shows up after I click a play button located in my main-menu user control.
Inside of a menu user control
private void PlayButton_Click(object sender, EventArgs e)
{
DifficultyScreenControl DiffScr = new DifficultyScreen();
this.FindForm().Controls.Add(DiffScr);
}
Also it is a good idea to either Dispose() or remove these screens one they can't be revisited again as it can free up resources being taken up by them.
Feel free to ask me questions or comment on things to change!

WPF Best Practice Coming From Windows Forms [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have extensive WinForms experience, but am new to WPF. Implementing Form design vision through XAML was easy enouhg to delve into, but I'm still a little unclear on what is expected from the M-V-VM programming style. I understand the principle of separating how things look from how they behave, but doing so sensibly in some cases continues to elude me.
For example, if I have a keypad with 9 buttons, and I want a means of enabling/disabling all of them through their IsEnable property, the Form designer in me wants to address them all in a code-behind method targeting them by Design Name. What is the WPF equivalent of such an operation? Am I expected to manage a series of bools in codebehind, and bind each one in the XAML to each respective button attribute? Thanks for any guidance. If this one scenario is explained, it should be sufficient to point me in the right direction
That specific problem is easily solved with binding. You would bind your buttons IsEnabled property to a public Property in your ViewModel and based on the logic contained in your ViewModel when that property value is changed your keypad button would get enabled or disabled.
As #GCamel mentioned you could also have a POCO class that would represent your button which would implement INotifyPropertyChanged interface with one of the properties being the IsEnabled property. You would add instances of this class to an ObservableCollection and when that IsEnabled property changes your button would become enabled or disabled in the UI.
I would also strongly recommend using one of the MVVM frameworks, my personal favorite is Simple MVVM Toolkit by Tony Sneed who also has a great article about the dialogs problem mentioned by #cwap Climb Onboard on the MVVM Message Bus
ideally, you would have an observable collection of button_info with IsEnabled property, icon and text - bind the collection to whathever suitable control like itemsControl, list, or grid and associate your button_info to a datatemple...you see what i mean ? no gui, no gui, just viewmodel and binding
or like this sample ???

C# Windows Form - access code [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to know where I can access the basic code, for example a "NumericUpDown" Element.
What I want to do:
Add Code to my NumericUpDown Element, for example:
Set the "Maximum"-Value to a variable embedded inside my Formclass code.
The Reason why I cant to it right now:
I just can access the NumericUpDown Element just in the Design View right now. There I can Input a value, but can't set it to the amount stored in a variable.
I just know, that If I double click the field, I get a "ValueChanged" Method into my code. But what I need to know: How can I access the "basic" Code of the NumericUpDown Element, where I could set the "Maximum"-Property?
I'm relatively new to programming. And I'm quite overwhelmed with a lot of things... So I COULD google for the problem but it would just take me way to much time.
Since I guess it's an easy answer for you guys, I post it here.
Thanks a lot!
You can access the Control's objects attributes by it's name.
For example:
NumericUpDown1 <- It's the name of your Control
In your C# code you can access all of it's attribtes and methods by puttin a period after it's name:
NumericUpDown1.Maximun = 100;
NumericUpDown1.Width = 250;
NumericUpDown1.Height = 10;
etc. You can serach it by "Control Properties" in google. Luck and effort! :P Remember to try and search a bit before asking. Don't wait for others to make your job. Luck! ^.^
You can access source code of components, but it won't help you. every component has interface and you can use it's interface to interact with it. Also you can override some methods of component to change their behavior.

C# - Drag and Drop files in win form [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to make like a container application where you can drag and drop files of any kind on the form and afterwards to be able to open it from there. I found some solutions where you can drag and drop files to a list view and you get it's path.. but is not how I want.. I want to have on my form in a panel or what ever is better like a shortcut of the file, an image or something to be able to see the file icon like is in explorer.
Have someone ever done something like this or point me to the right direction?
Set "Allow drop" property to "true" on your control and make use of Control.DragDrop event - it's exist on all controls, and it's invoked after drag'n'drop anything on anything(if "Allow drop" is true of course).
It this event-handler you can add new item to this or another control(ListView fits nicely to your needs), and for example to some "Dictionary" where you will store "Item and filename mapping".
Also you need to make handler for item click'ing - for ListView there a ItemActivate event. Inside this handler you can click execute default shell-action for this file by using Process.Start

Categories