Altering windows form from userControl - windows

i'm quite new with windows forms and i have a small issue.
i have a form that contains a userControl.
the form also contains a button with enabled = false, and upon some user selection in the userControl sets the button to enabled = true.
basically, i want to know what's the best way to change something in the form upon a change in the userControl.
I saw on the internet that event/delegates might be the answer, but it seems too complicated for such a small thing.
anyone has another solution?
thanks
Bosco

Events are your friends. They're really not that complicated. Just find an apropriate event for your user selection and set the button property.

User controls are meant to be hosted by different forms or other user controls. That's why they should be decoupled from their host controls.
IMHO best way to decouple the user control from its parent is to use events. Another way would be to implement the observer pattern. Events are a special implementation of observer pattern in .NET.

Related

Is there a JPanel equivalent for MFC

Im my application I want to implement the feature of when a user click on a button show a Panel which will consist of some user controls. I know In Java I can easily use Jpanel and use setVisible() method to get this done easily. But this is an MFC application. I couldn't find any built or customized component that I can use for my purpose.
I also tried GroupBox. But it is not grouping the components logically.
What would be the best approach for this?
As user1793036 says, start by creating a dialog resource and CDialog derived class for the panel. In the dialog resource properties turn off the Title Bar style. In the code call Create for the dialog and then SetWindowPos to place it where you want it to appear.
MFC is nothing but a thin wrapper over Win32 API for windows and controls. The core Win32 API doesn't provide any feature to group controls in a group-box or panel. One way is to have a window and make that window parent of all required controls. Unfortunately, this isn't easy to do.
I suggest you, since you are learning, to drop the idea. Instead, learn what you can achieve with existing set of features provided by MFC/Win32. With MFC/Win32, you would, mostly need to derive/subclass a class/window to get something fancy (such as colored list-control).

How to create a view for a single control?

What is the best way to create a view for a single control that I need to load into a Shell region in a Prism app. I know I can wrap the control in a UserControl, but I suspect there may be a better way.
I am working on a demo app to learn Prism 4. Each module will load a navigation button into an ItemsControl in a region in the Shell. These navigation buttons will function like the Mail, Calendar, and other buttons in Outlook.
I am creating the view in each module that will hold the module's navigation button. The simplest way to create the view seems to be to wrap it in a UserControl. My question is this: Is there a better way to do it? Thanks for your help.
If you need graphical control, what you are doing is the way to go. If you find yourself making all of the buttons look the same (copy - pasting) you might find that a menu registration service is the way to go.
You'd have a service like IMenuService that you register with your container and modules can come around and register menu items to. You can then create buttons for the module. I've provided a sample for this here:
http://dl.getdropbox.com/u/376992/CAGMenus.zip
Your question, though, seems to be about whether or not you need to wrap a control in a UserControl to register them with a region? If that's the question, I believe the answer is no, although you might amend your question to tell us what you are running up against that makes you think this.
I ended up wrapping the control in a UserControl, and it seems to work fine. I am still interested in seeing if there is a better way to load the button, so I will hold this question open for a few days.
Edit 02/22/2011: I tried using a control without a UserControl wrapper, and I got the following error:
Library project file cannot specify ApplicationDefinition element.
I wrapped the control in a UserControl and the error went away.

Win32 textBox in treeview

I want to add textbox in treeview as child of one of the parent node. Is it possible> If yes how to achieve this?
The native TreeView control isn't going to be helpful at all to make this work. Programming one yourself is a tricky proposition. It is however a very popular UI gadget. Any component vendor sells one, invariably called "TreeList".
You'll have to do some shopping if you want to use such a component from unmanaged C/C++. An ActiveX version of such a control is as close as you can get. Most component vendors have however put that in their legacy bag.
Depending on your requirements, you may be able to use the built-in label editing features of the Win32 tree view. See TVM_EDITLABEL.
To make an item act like an edit control, you could send this message yourself when the item is clicked. You could also use owner-draw techniques to make the item look more like an edit control when it isn't in label-editing mode.

Static UI vs Dynamic UI [closed]

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 4 years ago.
Improve this question
In some application with UI, what is better (easy, friendly, etc.) to a user:
UI is static (don't depends on user state). E.g user see some button, but it's grayed out or when it's clicked, a message, that this action is not applicable right now, is shown.
or
UI is dynamic (depend on user state). E.g. user don't see buttons, that are not applicable right now. But after some action, buttons may appear/disappear.
Sorry for my French:)
In my opinion, a static GUI with disabled controls is preferable.
When some options are not visible, the user will not know they exist.
Both of those styles have their uses. Remember that you should always use the right tool for the job and that there are (almost) no absolutes in creating software.
A static UI with grayed out elements is preferable in most cases. By providing a simple non-obtrusive message (don't show a modal message box for instance) when the user clicks or tries to interact with the grayed out elements, you can train your users.
What really happens in most cases is that there is a grayed out menu and your users are left wondering what they need to fix to be able to click on that element. This is bad UI design.
A dynamic UI is also relevant if you have an extensive administration section that the logged in user should NEVER be able to use. By hiding the administration section, you avoid confusion and interface "overload" for users who will NEVER interact with the hidden interface elements.
A dynamic UI is required in applications like Adobe Photoshop. There are literally thousands of commands and menu items possible in Adobe Photoshop. The only way that any user could comprehend the interface is by hiding and showing user interface elements depending on the state of the application.
I always recommended a UI that is as unchanging as possible:
Don't surprise users
I don't think there is a right or wrong answer to this question, I think it is just a matter of opinion/preference.
Personally, I would expose all functionality to the user and just grey it out when it is not accessible. However, there are some situations where I would consider removing the buttons from view e.g.
Administrative options (probably don't want to expose this to users with lower priveledges)
RunOnce functionality (activating product/registering)
Reasons for this is there is no point in exposing functionality when the user is not meant to access them or if the functionality is just going to sit there greyed out forever...
Hope that helps.
If an action is not available
because the profile of the user
forbids its use do not show it at
all
If an action is not available only
because another action must first be
completed either :
Grey it out or
Leave it activated but on execution display a
message with a clear explanation of
why it cannot be executed
Make the action unavailable (by hiding, disabling, or using an error message) only if the action is logically impossible for the current state of the task, or to encode organizational rules on the actions certain users are permitted to do (e.g., privileges/permissions). Whenever possible make the user actions always available:
Use status indicators to discourage unnecessary actions, but allow them anyway.
Use verification and undo to prevent permanent damage from unadvisable actions, rather than disallowing the actions. Users may need to do something some day that is usually “unadvisable.”
Alter app design to make actions always possible in some way. For example, if a field needs to be filled out before an action can be done, prompt the user for the field, rather than disallowing the action.
Control user behavior through organizational policy, not software. Policies are easier to change when the business rules change or when there’s an exception or emergency.
Use disabling when:
The user can do something in the app to make the action available.
Availability is achieved through controls in the same window or its parent.
The user can easily figure out which control does this.
Use toggling controls rather than disabling for turning processes on and off.
Use read-only text boxes rather than disabled text boxes for data that is applicable for the current state unchangeable by the user.
Use hiding (“dynamic UI”):
For actions that are never available to the user in his or her current job.
For indicating different virtual places or things (e.g,. pages on a tab control, where each “tab” is a different place or thing). Make sure visual design is compatible with this: if you are representing different places, then make it look like different places (e.g., the way tabs do)
For swapping large numbers of controls with alternative controls.
Use layout, symbols, and text to explain unavailability, especially disabling. For example, mark your required fields; use tooltips to say why a button is disabled.
Use error messages rather than disabling or hiding when there no other means to indicate graphically or textually how to make an action available.
Further details and rationale at http://www.zuschlogin.com/?p=40.
I nearly always keep the UI static and simply disable (grey out) components that aren't applicable at this moment in time. It can be jarring to the user and confusing if components move around as you show/hiden them as the state changes.
I have seen good examples of both, and bad examples of both.
Your primary goal should be in making sure that your UI design (whatever route you choose) makes the entire process logically sensible to your intended audience.
dynamic is better if you don't want to frustrate your users
Well, that's the idea behind the latest MS Office, right? Controls that are around based on context. That, versus older versions with lots of grayed-out menus and toolbar buttons.
I worked for a number of years on control systems and in those environments, we mimicked the hardware controls (toggles, dials, buttons) that were, of course, static though not always usable. This was a customer requirement and their position was that the operator using the system expected button X to always in the same place. But from the designer and developer standpoint, I was frustrated by the cluttered UI and didn't like it when 95% of the buttons on a screen were grayed out.
I think that it will depend on your audience and the domain and customer requirements. In my shop, I make things dynamic and offer controls that make sense based on context. Typically, we don't show grayed out buttons or menu options that aren't available in the current context. Once the users recognize that they follow certain workflows and those involve particular UI elements when appropriate, they have no problems with (and probably prefer) a dynamic UI.
Less is better.
Why not do both and let the A/B testing tell you what your users prefer?
I think it's better to focus on the user productivity and on the business the software is implementing.
To show operations that does not make sense for a specific user or in a specific moment will not help, disabled or not.
For example, if you have a software that is used in several departments of an organization, each user/department will only be interested in the part of the software that implements the part of the business he is involved to. Anything else is useless for him and only will make the software experience worst. The same applies for a screen that is usefull for a user but shows useless options.
I'd suggest prototyping both and asking your users (or a representative sample) which they prefer and why.
Just to re-iterate what Mitch Wheat said really.
If you make buttons disappear and reappear depending on user actions then there is the danger that the user might think that they've done something that's broken the application.
You are also hiding actions from the user, so it will be harder for them to discover what it can do.
Disabling buttons is a well known paradigm and users will be able to see everything that your application can do and will experiment to see how to enable them.
I think it depends on what users you want to hide design for but in general I would opt for the static version. Don't forget that a user interface doesn't only provide functionality but also information. If you grey out a button you inform the user about it's state (by what he can do and what not) more clearly than removing buttons.
The remove button aproach can work for users that in general have good understanding of the system like admins. But I think you should use this with causion
Grayed out buttons are better, because then the user will know that under some situation such a function is available (and depending on the context the user might be able to guess when it is enabled), and the visual cue of being grayed out will signal to the user that the button can not be clicked, so the user will not try to click it (the problem with a message after clicking is that it comes too late - the user already made a mistake).
Whatever you choose, use constant positions of the buttons. Users often are not read text on the buttons.
Depends. But a clear and compact GUI is a nice thing to have. Why bother with 10 fields/controls you cannot change or use at all. For example on stackoverflow you have a reduced UI if you only have a low reputation, because it doesn't matter at all to the user, that one day he might be able to use them. Another thing is that controls (with borders) usual take more space than just text. If you have information, that currently cannot be changed, I would present them in a very compact text field/label. Depending on the information it even could be placed outside or far way from the form.
According to Joel - neither :-)
Both can make sense, as long as you use paradigms the users are familiar with.
The tab control is basically a dynamic UI that changes depending on the state.
Consistency is probably the most important thing when designing an UI. If buttons pop in and out, they are seen as a visual stimulus, and the user will "spend" attention looking at them.
A subtle, but clearly disabled button (not disappearing) is my preffered choice for designing UI....
.. So I guess that's option 1 :)
A combination of the two.
If a function is not applicable in the current state, disable the button but also place an icon next to the button and associate a tooltip with the icon. The tooltip should explain why the user can't use the button right now.
Attaching the tooltip directly to the button doesn't work so well. Most users won't even hover over the button as they won't expect it to do anything.
And avoid exclamation mark icons. They suggest the user has entered an invalid value (unless they actually have.)
I'd like to say I always do this, but unfortunately it does take significantly more coding time, and clients aren't always willing to pay for that.
A modal UI introduces mode errors. Always.
You currently seem to want to choose between two different ways of presenting a modal UI. From those I'd say the first one is superior (unless you really have many possible commands, see the Office 2007 UI for a good example how to handle this, but it's not common to have that many).
If you have the space and you haven't too many controls then I'd really go with disabled controls as it shows th user what is possible. Furthermore you might want to make it really clear which mode the UI is in (not just from the buttons that are enabled). I've seen user interfaces where you had disabled buttons but the user couldn't figure out what he has to do to enable them.
In any event be sure to do usability testing to find out what way is less error-prone on behalf of your users.
I like to keep all advanced options hidden under a "More >>"/"Less <<" button, or "Advanced Mode" checkbox, depending on the context and application.
Once clicked/checked, the window expands to reveal more options.
In terms of action availability though (like a Wizard featuring Next/Previous buttons) I always show them, and enable/disable them according to what functionality is possible.
The dynamic UI is done like the UI may keep changing. The fields may keep changing. So depending upon that the information of the field fetched from internet the ui is designed.
Rembr! all the similar fields have same design so u can keep changing the UI design and hence the application. without uploading the newer version of the application to the cloud or play store you can change the design of the UI.
As a example the UI pattern and fields are filled in the excel sheet and uploaded to cloud and the app has the access to download the excel sheet.
the above explanation holds good for an android dynamic app development

Best practices of building composite custom controls WPF

Can You tell me about subj?
For example I need to create new custom control that must be derived from datagrid and toolbar. And I want that new control to expose/propagate properties of base controls in order they to be accessed easily. The only way I know is deriving a class. Then descendant automatically gets all properties of ancestor. But multiple deriving in C# is prohibited, so I don't know how to expose properties and other behavior of second control... Styling and templating of such custom control is also needed.
Thanks!
In WPF inheritance is "out". ;O) Actually, it was complicated before WPF already, but with WPF you get various really powerful alternatives.
For the basic control I thing you'd better go with composition, create some usercontrol and make it contain a ToolBar and a DataGrid. You can then expose these as public properties, if you need to manipulate them from outside.
For special feature additions, attached properties are a very versatile mechanism.
Watching a window from windowsclient.net is a good place to start.
Make sure you understand dependency properties well.
Reading wpf blogs is my best guest for what to do then.

Resources