When I add language support to the buttons in the WinUIMessageBox and change the language at runtime, the language of the buttons does not change.
public class CustomDxMessageBoxLocalizer: DXMessageBoxLocalizer {
protected override void PopulateStringTable()
{
this.AddString(DXMessageBoxStringId.Cancel, Localization.GetValue("CCancel"));
this.AddString(DXMessageBoxStringId.Ok, Localization.GetValue("Ok"));
this.AddString(DXMessageBoxStringId.Yes, Localization.GetValue("Yes"));
this.AddString(DXMessageBoxStringId.No, Localization.GetValue("No"));
}
}
WinUIMessageBox.Show(Window.GetWindow(ActiveDesktopWorkPlace.RootWindow)
Localization.GetValue("ApplicationCloseCommandQuestion"), "XXXXX",
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes,
MessageBoxOptions.None, FloatingMode.Window);
When the language is changed at runtime, I expected the language of the text of the buttons to change as well. But the text of the buttons did not change.
Related
I haven't done this for a while so am not quite sure how to do what I need, but I am sure it is pretty simple.
Basically, I have a form with a navigation pane. I want to make it so when a user clicks a button on that pane, say 'Home' it changes the content on the form, but doesn't actually switch to another form, if you get me?
As in, I would like the navigation pane to stay as it is the entire time and I only want the content of the form to change. It is almost like the 'TabControl' tool in Visual Studio's 'Toolbox' although instead of the tabs being directly above the content, I want them to be buttons displayed in a side pane. See the image below for a better understanding. Thanks!
(Side pane, and header stays the same regardless on what button is pressed, but the content changes.)
I'd implement this using UserControls. One UserControl is shown when a button is clicked. I'd create an interface (for example IView) that would be implemented by each UserControl that declares common functionality, like for example a method to check whether you can switch from one to another (like a form's OnClosing event) like this:
public interface IView
{
bool CanClose();
}
public UserControl View1: IView
{
public bool CanClose()
{
...
}
}
public UserControl View2: IView
{
public bool CanClose()
{
...
}
}
Then, switching views is quite easy:
private bool CanCurrentViewClose()
{
if (groupBox1.Controls.Count == 0)
return true;
IView v = groupBox1.Controls[0] as IView;
return v.CanClose();
}
private void SwitchView(IView newView)
{
if (groupBox1.Controls.Count > 0)
{
UserControl oldView = groupBox1.Controls[0] as UserControl;
groupBox1.Controls.Remove(oldView);
oldView.Dispose();
}
groupBox1.Controls.Add(newView);
newView.Dock = Dock.Fill;
}
In a button you could do this:
private void btnHome_Click(object sender, EventArgs e)
{
if (CanCurrentViewClose())
{
ViewHome v = new ViewHome();
// Further initialization of v here
SwitchView(v);
}
else
{
MessageBox.Show("Current View can not close!");
}
}
I've successfully used this approach on many occasions.
Simplest way is to place multiple Panels as content holders, implement content manager which keeps references to Panels and with it show/hide desired panel.
Simple, but for smaller apps it will work
You can simply use a TabControl which has as many TabPages as you want. For the TabControl you can set the Alignment property to Left
I create a user control and add a textbox to it. In my windows form I add the user control i created and add a textbox and a button. How to copy the text I input from the textbox of Form to textbox of Usercontrol and vice versa. Something like
usercontrol.textBox1.text = textBox1.text
You could add to your User Control code a public property that delegates into the TextBox's Text property:
public string MyTxtBoxValue { get { return this.txtBox.Text; } }
And you could also have a setter to that, of course, if needed.
What you don't want to do, however, is exposing the whole TextBox by making it public. That is flawed.
From Form to Usercontrol
Form Code
public string ID
{
get { return textBox1.Text; }
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
userControl11.ID = ID;
}
Usercontrol Code
public string ID
{
set { textBox1.Text = value; }
}
There are multiple ways to access your user control text box data. One way to accomplish this would be to expose the text box on the user control at a scope that can be accessed via the form it's loaded on. Another way would be raising an event on the button click of the user control and subscribing to it on the parent form.
Although some stuff are inherited when creating a custom user control, for the most part you have to define your own properties. (like text value, etc..)
I would take a look at this:
http://msdn.microsoft.com/en-us/library/6hws6h2t.aspx
good luck!
I am designing a comparison dialog (shows several widgets with their characteristics in a grid). There is a features section where all available features are listed with a check box for each one. If the part has that feature, the checkbox is checked. These checkboxes need to be read-only so I've isEnabled=false. However visually the checkboxes (and the label content) show as greyed out.
Here are some important points:
The checkbox is a visual indicator of whether a part has a feature. There is no requirement for interaction.
The requirement is for a checkbox; I'd have to convince the powers that be to use something different.
What I want is an easy way to style/controltemplate a checkbox (and it's content) so it looks enabled, but doesn't react to user input.
Microsoft provides some of their default styles on MSDN and you can find the default style for a checkbox here: http://msdn.microsoft.com/en-us/library/ms752319(v=vs.85).aspx. Copy this style into your project, remove the Trigger for IsEnabled and set the style for your checkboxes to this new style.
On a side note, I'd recommend copying the style into a separate ResourceDictionary for reusablitiy and to keep the style from cluttering up your xaml files.
Create a custom control by inheriting from CheckBox, and in its constructor create a Click handler for it. Within that Click handler, put the following code:
((CheckBox)sender).Checked = !((CheckBox)sender).Checked;
Here's a complete example.
For Windows Forms:
namespace System.Windows.Forms
{
public class UnChangingCheckBox : System.Windows.Forms.CheckBox
{
public UnChangingCheckBox()
{
this.Click += new EventHandler(UnChangingCheckBox_Click);
}
void UnChangingCheckBox_Click(object sender, EventArgs e)
{
((CheckBox)sender).Checked = !((CheckBox)sender).Checked;
}
}
}
For WPF:
namespace System.Windows.Controls
{
public class UnchangingCheckBox : System.Windows.Controls.CheckBox
{
public UnchangingCheckBox()
{
this.Click += new System.Windows.RoutedEventHandler(UnchangingCheckBox_Click);
}
void UnchangingCheckBox_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (((CheckBox)sender).IsChecked.HasValue)
((CheckBox)sender).IsChecked = !((CheckBox)sender).IsChecked;
}
}
}
If you place the above code in a new class in your Windows Forms or WPF project, they'll appear as new tools in your toolbox. Then all you need to do is drag your new "UnchangingCheckBox" control onto your form where you were using a CheckBox. You don't need to do any coding on your form.
Using this approach your code will still be able to do everything you could do to a CheckBox (set its value, etc). It's only user interaction that's been disabled in a way that doesn't interfere with the visual style.
The solution suggested above works well for Windows Forms, but I see what you mean about WPF and the check mark appearing for a second.
Try this instead:
namespace System.Windows.Controls
{
public class UnchangingCheckbox : CheckBox
{
public UnchangingCheckbox()
{
this.IsReadOnly = true;
}
public bool IsReadOnly
{
get { return !this.IsHitTestVisible && !this.Focusable; }
set
{
this.IsHitTestVisible = !value;
this.Focusable = !value;
}
}
}
}
You acquire a property called "IsReadOnly", which by default is set to true, and has the behaviour you require without the annoying "checkmark appears for a second" behaviour.
I've been experimenting with enabling anti-aliasing of text in various controls in a Windows Forms Application.
I did a bit of research and it seems like the solution is to create a custom control and to override OnPaint() to modify the TextRenderingHint. I have used this approach successfully on Label and Button controls, but it appears not to work for TextBox or RichTextBox controls.
Here is the code I am using to enable anti-aliasing in a custom Label control:
public partial class CustomLabel : Label
{
private System.Drawing.Text.TextRenderingHint _hint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
public System.Drawing.Text.TextRenderingHint TextRenderingHint
{
get { return this._hint; }
set { this._hint = value; }
}
protected override void OnPaint(PaintEventArgs pe)
{
pe.Graphics.TextRenderingHint = TextRenderingHint;
base.OnPaint(pe);
}
}
Using the same approach for a TextBox or a RichTextBox does not appear to work.
The application I'm creating deals primarily with text input and I would really like to use anti-aliasing for all of the displayed text, especially text being typed into a TextBox or RichTextBox or a custom control.
I have a library. In the library, I have a button with a Green background color and Text as Go Green.
Now I made a winform project and dragged my Go green button in the form. On running the application, I noticed that the button color is changing to green but text is displayed as button1 (name of the class library).
My library looks like:
public class button : Button
{
public Seats()
{
button.BackColor = Color.Green;
button.Text = "Go Green";
}
}
I discovered that it is happening because InitializeComponent() method is called in the constructor of the form. And in designer.cs,
button.Text = "button1";
is called. How can I avoid that to happen. I want my text to be visible from my class library.
Note: When I manually removed the above code from the designer.cs, everything was working fine.
Easiest way - override button's Text property and make it hidden to designer serialization:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string Text
{
get { return base.Text; }
set { base.Text = value; }
}
Designer will add default button name, but when you build application, your text will be shown.
UPDATE: Another (harder) way - provide to designer default property value for your button. In this case you need reference System.Design.dll which is available only for full version of .net framework (not client profile version).
First: create control designer for your button
public class GoGreenButtonDesigner : System.Windows.Forms.Design.ControlDesigner
{
public override void OnSetComponentDefaults()
{
base.OnSetComponentDefaults();
Control.Text = "Go Green";
}
}
Last: add Designer attribute to your custom button class
[Designer(typeof(GoGreenButtonDesigner))]
public class GoGreenButton : Button
{
//...
}
That's it. Now when you drag button to form, it will have default text "Go Green" without any additional compilations.