|
could you make a wpf version?
|
|
|
|
|
Hi there,
I'm trying to your code but I'm not able to get it to work in the way I would like.
This is what i'm trying to do:
In my application i need two differtent option dialogs.
The first one is used to set application options.
The other one has to be for project properties.
I've managed to adjust the code, so depending on what the user wants to see the right options are shown:
Simply by provideing a enum to the constructor.
public enum DialogType
{
Project,
Application
}
public OptionsPanel(DialogType type): base(GraphicEditor.Properties.Settings.Default)
{
InitializeComponent();
if (type == DialogType.Project)
{
Panels.Add(new HospitalPanel());
Panels.Add(new CommonPanel());
Panels.Add(new CTGPanel());
Panels.Add(new DatabasePanel());
}
else
{
Panels.Add(new BasicSettingsPanel());
Panels.Add(new DevicesPanel());
Panels.Add(new DefaultDatabasePanel());
}
So far so good.
But as you can imagine, every time I start a new project in need all of the project properties toe be reset to the default values.
I added a function like this:
public static void SetDefaultSettings()
{
GraphicEditor.Properties.Settings.Default.AllowFingerprint = false;
GraphicEditor.Properties.Settings.Default.ArchivePath = @"G:\Archived\";
GraphicEditor.Properties.Settings.Default.CTGAspectRatio = "2";
GraphicEditor.Properties.Settings.Default.Culture = "";
GraphicEditor.Properties.Settings.Default.Database_Name = ""
GraphicEditor.Properties.Settings.Default.Database_Password = "";
GraphicEditor.Properties.Settings.Default.Database_Servername = "";
GraphicEditor.Properties.Settings.Default.Database_SystemAccount = "";
GraphicEditor.Properties.Settings.Default.EditPartus = false;
GraphicEditor.Properties.Settings.Default.EnableSSO = false;
GraphicEditor.Properties.Settings.Default.HospitalNumber = " ";
GraphicEditor.Properties.Settings.Default.HospitalCity = " ";
GraphicEditor.Properties.Settings.Default.HospitalName = " ";
GraphicEditor.Properties.Settings.Default.HospitalCode = " ";
GraphicEditor.Properties.Settings.Default.Save();
}
This code will be called inside the constructor:
public OptionsPanel(DialogType type): base(GraphicEditor.Properties.Settings.Default)
{
InitializeComponent();
SetDefaultSettings();
if (type == DialogType.Project)
[....]
When I start the application for the first time all goes well.
When I create a new project insde my application, the settings are set by the SetDefaultSettings function.
But when I want to create another project inside my running application, the properties cannot be set anymore?
It looks like the settings are somehow locked ?
I've tried as mush as I could think of, and for a moment I thougtht the GraphicEditor.Properties.Settings.Default.Reset(); function would do the trick, But altought the settings are indeed reset, they cannot be altered anymore.
I think it has something to do with the object being in use.
This is how I show the dialog:
public DialogResult showOptionsDialog(OptionsDialog.DialogType dialogType)
{
OptionsDialog.OptionsPanel optForm;
if (dialogType == OptionsDialog.DialogType.Project)
{
if (ProjectOptions == null)
{
ProjectOptions = new OptionsDialog.OptionsPanel(dialogType);
}
optForm = ProjectOptions;
}
else
{
if (ApplicationOptions == null)
{ ApplicationOptions = new OptionsDialog.OptionsPanel(dialogType); }
optForm = ApplicationOptions;
}
return = optForm.ShowDialog(this);
}
Please advice.
Thank you
modified 17-Sep-13 7:42am.
|
|
|
|
|
Hi,
I would like to use your code in a project of mine that I intend on releasing under GPL license. Currently I am using some of your app options code, thus I need to know if I have permission to use it and what license it is under so that I can explicitly state that in my code. CodeProject has some useful information on the subject here: http://www.codeproject.com/info/Licenses.aspx[^].
- Jeremy
P.S. Thanks for releasing this code, as it has been very useful!
|
|
|
|
|
Hi Gladstone,
In my settings, I need to show a datagridview bound to a datatable, including Add/Edit/Delete buttons to add rows.
Whilst binding a property setting to a simple control like a textbox is straight forward, how do you do it for a DataGridView? I've checked all the binding properties for the control and there's nothing obvious that one could use.
Have you any ideas or perhaps a different approach?
Cheers,
Michael.
Michael Mussulis
Web Developer, Software Programmer
|
|
|
|
|
Hi,
Firstly, nice control, great job. Second, how do I set the categories treeview to expand all nodes by default?
I looked around and couldn't figure it out.
Cheers,
Michael.
|
|
|
|
|
I don't think the treeview control allows you to do this automatically. You have to do it manually, by accessing all the item and expanding them. Would not be hard to add a flag to the OptionsForm class and then do this at the loading time. Hope this helps.
|
|
|
|
|
Gladstone,
Thanks for your reply. I solved the problem by adding a public class to the options form:
public void ExpandCategories()
{
CatTree.ExpandAll();
}
My question was more on the lines whether you had some hidden option somewhere.
Thanks,
Michael.
|
|
|
|
|
Hi
I add a ComboBox to one panel
this.cboVerification.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::Options.Properties.Settings.Default, "Verification", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
this.cboVerification.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboVerification.Items.AddRange(new string[] {"Yes","No"});
this.cboVerification.Text = global::RDOptions.Properties.Settings.Default.Verification;
but when I select another value from the ComboBox, Applay is not enabled !!!
Do I have to change the binding to "SelectedIndex" insted of "text" ??
thanks
Khayralla
Hi
I notice that the above problem is related to
cboVerification.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
when i comment the above line it will work but user can chane the text in the ComboBox !!!!
modified on Wednesday, April 9, 2008 12:18 PM
|
|
|
|
|
Yes of course it does because the Text property for a combobox returns the text typed by the user in its text field and when the style is set to DropDownList there's no such field. Instead you must set the binding on the SelectedItem property.
|
|
|
|
|
OK,
1) what about list box, if I have a text like "doc,exe,html,pdf" and I would like to add them to a list box where each extenstion must be in a saprate line. Do you have an idea how to implement this case.
2) if I want to retrive from and save to a different xml file rather than the Application configuration, so it can be used by other components. How can I implement this case.
Thanks
Khayralla
|
|
|
|
|
for 1) I posted here may be some body need it one day.
I add a label and bind it. when the form is loaded or after initializing controls, i add
this.list1.Items.AddRange(this.lblIgnoreValue.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
to add a new entry to the list
this.list1.BeginUpdate();
this.list1.Items.Add(s);
this.list1.EndUpdate();
string[] list = new string[this.list1.Items.Count];
this.list1.Items.CopyTo(list, 0);
this.lblIgnoreValue.Text = string.Join(",",list );
list = null;
in case you remove an entry from the list
int index = this.list1.SelectedIndex;
this.list1.BeginUpdate();
this.list1.Items.RemoveAt(this.list1.SelectedIndex ) ;
this.list1.EndUpdate();
string[] list = new string[this.list1.Items.Count];
this.list1.Items.CopyTo(list, 0);
this.lblIgnoreValue.Text = string.Join(",", list);
list = null;
so this will preserve Applay button behaviour.
Khayralla
|
|
|
|
|
The CategoryPath property of the OptionsPanel should have the attribute Localizable[true] to allow localization of the entries in the category tree.
|
|
|
|
|
Hi,
I want to localize the form. I switched localizable to true on the form. After reopening the project i got this error:
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.
SplitterDistance must be between Panel1MinSize and Width - Panel2MinSize.
Hide
at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at System.ComponentModel.ComponentResourceManager.ApplyResources(Object value, String objectName, CultureInfo culture)
at System.ComponentModel.Design.Serialization.ResourceCodeDomSerializer.SerializationResourceManager.ApplyResources(Object value, String objectName, CultureInfo culture)
at System.ComponentModel.ComponentResourceManager.ApplyResources(Object value, String objectName)
Does anybody have an idea to fix or workaround this?
Stefan
|
|
|
|
|
I've found a workaround. See details here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2281390&SiteID=1[^] Add the bold lines to the constructor:
public OptionsForm(ApplicationSettingsBase settings)
{
InitializeComponent();
// Microsoft bug in the generated form code?
OptionsFormSplit.Panel1MinSize = 125;
OptionsFormSplit.Panel2MinSize = 350;
OptDescrSplit.Panel1MinSize = 35;
OptDescrSplit.Panel2MinSize = 17;
OptionsSplitContainer.Panel1MinSize = 215;
OptionsSplitContainer.Panel2MinSize = 64;
|
|
|
|
|
It seems that only one setting file can be used. I've split my settings file into logical groups. This makes it easier for me to manage the code and different assemblies can load their setting panels into the options form for a central location.
How do you suggest support for multiple setting files?
|
|
|
|
|
There are two ways I can think of to meet your needs. First one (I don't know how and if this is actually possible) you can override the base ApplicationSettingsBase class to support multiple settings file instead of only one OR you can change the OptionsForm constructor from this:
public OptionsForm(ApplicationSettingsBase settings)
to something like this:
public OptionsForm(ApplicationSettingsBase[] settings)
Then you'll change the _AppSettings field type accordingly and replace the following line in the constructor:
_AppSettings.SettingChanging += new SettingChangingEventHandler(_AppSettings_SettingChanging);
with something like this:
foreach (ApplicationSettingsBase settingGroup in settings)
{
settingGroup.SettingChanging += new SettingChangingEventHandler(_AppSettings_SettingChanging);
}
Theoretically, it should work. To keep compatibility you could then re-add a constructor which accepts only one instance of the ApplicationSettingsBase (like the original one) and call the changed constructor within it. Something like:
public OptionsForm(ApplicationSettingsBase settings)
: this(new ApplicationSettingsBase[] { settings })
{ }
|
|
|
|
|
Wouldn't it be easier to do all the processing of the saving in each optionpanel instead of the optionform. just curious. that's the approach i was thinking was more like what i had in mind.
|
|
|
|
|
I Created a Project just as you explained. Started it to test and it worked. When i went back to my UserControl inherited from OptionPanel i get this designer error :
DesignTimeVisible
Hide
at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertiesFromResources(IDesignerSerializationManager manager, Object value, Attribute[] filter)
Any Ideas ?
Banshee for windows YAY !!!
http://sourceforge.net/projects/banshee32
|
|
|
|
|
It seems that the designer is not able to hide the control at design time but I can't really guess what's the problem with such little information. Perhaps if you could provide some more details I could be of some help, I hope.
|
|
|
|
|
My colleage noticed that the following code:
MyOptionsForm optForm;
private void Options_Click(object sender, EventArgs e)
{
DialogResult optionsResult;
// store current setting
bool PrevTranslationTables = Properties.Settings.Default.TranslateText;
if (optForm == null)
{
optForm = new MyOptionsForm();
}
optionsResult = optForm.ShowDialog(this);
// now that user has finished playing with settings....
if (optionsResult != DialogResults.Cancel)
{
// Reload translation tables
LoadTranslationTables();
}
}
always returns "Cancel".
I believe the OptionsForm_FormClosing(...) should be modified to:
private void OptionsForm_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Visible = false;
if (_OkClicked)
{
e.Cancel = false; //I added this line
OnSaveOptions();
}
else
{
OnResetOptions();
}
}
Michael
\|/
^O^O^
——o00o—0—o00o——
If we knew what it was we were doing, it would not be called research, would it? --Albert Einstein
|
|
|
|
|
I was noticing that the apply button was always disabled and my options were not being saved. I stepped through the code and saw that you are continually calling this method in OptionPanel.cs:
<br />
protected void OptionsSaving(object sender, EventArgs e)<br />
{<br />
}<br />
Is there supposed to be something in it?
Which method is actually saving the options to the settings file?
-- modified at 15:14 Monday 19th February, 2007
The Apply button was never set because I forgot to add the :base (settings) to my constructor.
Michael
If we knew what it was we were doing, it would not be called research, would it? --Albert Einstein
|
|
|
|
|
OptionsSaving is called each time options are being saved but before they actually are so. You can add your logic here, or make the method virtual to let inheritors to add logic by their own. Options are currently saved in the OptionsForm class (in OnSaveOptions method) and not in the options panel in which only graphical context should be handled.
|
|
|
|
|
Really nice solution. It's exactly what I would like to use in my app, except for the keyboard navigation. When tabbing from the treeview I would like to have the first control on active page to get the focus and when tabbing from the last control on a page it should be nice if the OK button get the focus. When the last control is activated on a page, it's not possible to tab to the next control (OK button).With Shift+TAB it seems to work as I want, but not with TAB. How do I solve this problem?
P.Burman
|
|
|
|
|
This is the first solution I was thinking at. For the treeview you have simply to override the OnKeyDown of the treeview (or register a new event handler for the same action, that is the KeyDown) and here check if the tab is pressed and do what you need (that is, select the visible panel). For the last-panel-control to ok-button you have to find in the OptionsPanel base class, which control inside the panel has the last tab-order value, then you can register a new KeyDown event handler for that control and in the handler select the ok-button. As I said this is the first solution I'm thinking at, I've not tried it so I can't be sure it will work.
|
|
|
|
|
Thank you for your fast respond.
I will test try to do that.
Best regards// Per
|
|
|
|