In window forms, can we access name property of timer control or can we change the name property. Help me thank you.
If you are talking about System.Windows.Forms.Timer class, then there is no such property within this class or its ancestors. If you need one, just create your own timer based on System.Windows.Forms.Timer.
Related
What is the default WindowProc of a list-view control before I change it using SetWindowLong()?
That's determined by the system when it registers the window class. It is presumably implemented in comctl32.
There's nothing special about one of the built-in window classes in this regard. Just as is the case for a user defined class, the default window proc is whatever was specified when the class was registered.
to get the wndproc for a window class use GetClassLongPtr with nIndex=GCLP_WNDPROC, also you can use SetClassLongPtr to super class the window.
I need to do a quick sample WPF application where the controls on the forms should be made visible or hidden based on the user roles.
Something like this will be great,
How to manipulate WPF GUI based on user roles
I am not sure where to put the XAML defined in the thread(<Control ) so that the every control in the form uses RoleToVisibilityConverter to show or hide the controls.
i am very new to windows dev..could you please help me ?
Regards
Bala
You could solve this by binding the Visibility to a corresponding property in your code-behind/ViewModel.
This is an example from a binding in one of my testcontrols using WPF (in combination with Caliburn):
Visibility="{Binding Path=IsAdmin}"
Here I have a bool property in my ViewModel called IsAdmin.
For me, the easiest way was creating a global variable in my app. For that, go to your Project->Properties->Settings.settings and create a new variable (called, for example, Administrator), and set it to True of False depending on what you want to do. Something like this:
Then, at your MainWindow, when its initialized, you can write this:
if (!Properties.Settings.Default.Administrator)
{
DisableSettings();
}
And then, disable the fields you want to.
Please advise me. Winforms app, C#. I have a user control (UC) that contains a DataGridView.
Firstly, I have a boolean public property in the UC called "IsComplete". in the RowEnter event of my DGV, Im able to set the property accordingly.
Secondly, I successfully instantiate and load this UC into its designated area in my Main form.
PROBLEM:
I would like the 'Enabled' property of a control in my Main form to respond to the IsComplete property in my UC automatically when it changes.
Is this possible? All my searches on Google refer to examples using INotifyPropertyChanged, but only on the same class.
I would certainly appreciate any help on this. TIA!
-cheers!
Why you don't fire off an event when your IsComplete property gets set? This sounds like a pretty trivial thing to do with either events or delegates in c#?!
If you have more complex sort of requirements you should look into the the observer desgin pattern here and here.
It basically allows you to register listener objects to whatever object that changes its states and then action accordingly.
I have a boolean global variable that is set true if an administrator is logged in and wants to amend the content of the lists and comboboxes. As a result, a button is displayed beside each combo to display a dialog box when clicked.
If I was not coding for WPF, I would probably include some sort of code similar to the following in each Window:
If gAdminEditLists=True Then btnUpdateCombo.Visibility=Visible Else btnUpdateCombo.Visibility=Collapsed
In my WPF app, I am using a style for the button that is used throughout the application and I am guessing that the best way forward is to set the Visibility of the button within the style based upon the value of the gAdminEditLists variable.
The only way I can see of doing this is to use some sort of converter within the button style that converts the gAdminEditLists value to visible or collapsed.
I'm not too sure how to proceed with this or whether this is the best approach, so any suggestions would be appreciated.
well your problem is that you're using a global variable isn't it?
if you had a property that implemented notification or a dependency property you would be ok. the closest thing to a global variable is a property on the app ( i assume thats where your global is )
defining dependency properties on app.xaml, however you could just use INotifyPropertyChanged.
binding to properties in app.xaml.cs
enjoy!
Have a look at the BooleanToVisibilityConverter class in the System.Windows.Controls namespace.
I'm creating a silverlight user control that I should be able to drag and drop via blend. But this control needs to accept a map that is already on the page.
For eg.
Main.xaml contains a map control.
MapEditor.xaml contains buttons and other controls. In the .cs file, it needs to access a map control (the one in Main.xaml).
How do I go about getting this done?
I was thinking about adding a parameter in the contructor for MapEditor but how would I pass in the map as a parameter in design mode?
Thanks.
ps. I'm going to break out this control into a silverlight library so it could be used in multiple projects later.
You don't want to be giving your control a parameterised constructor, XAML will only construct types using their default constructor.
Simple Approach
The easiest approach would be to add DependencyProperty to your control to which you would assign the Map control (I'll use the type name MyMap in this example):-
public MyMap Map
{
get { return (MyMap)GetValue(MapProperty); }
set { SetValue(MapProperty, value); }
}
public static DependencyPropery MapProperty = new DependencyProperty("Map",
typeof(MyMap), typeof(MapEditor), new PropertyMetaData(null));
Now in Blend the Map property will appear in the Miscellaneous category in the Properties tab. You can then use the "Element Property" tab of the "Create Data Binding" to select the Map control to which it should bind.
Hard Core Approach
That said I would be inclined to build a proper customisable control following these guidelines Creating a New Control by Creating a ControlTemplate. With the addition that I would extend the ContentControl base class and include a ContentPresenter at the heart of the template. The control would make the assumption that the child control is a MyMap control.
This approach allows the entire appearance of the MapEditor control to be styled in Blend and it allows the Map control that is to be "edited" to be drap-drop onto the MapEditor as a child control.