Change application layout Right to Left - winforms

I have an windows application developed in C#.NET. We have to deliver this application in country where language is Right-To-Left (Arabic).
Is there any way where I can write code to detect Locale and according to that Layout get changed. Means If there is an panel containing Label at left side and textBox at Right side then in Arabic (ar) Locale it get changed to TextBox at left side and Label at Right Side.

I don't think you can do this out of the box.So a little bit of code must be written.That means for instance that you can create custom controls that inherit from the control you are using,say Panel.
public class MyPanel:Panel
{
public void SetLayoutToArabic()
{
foreach (Control oneChildControl in this.Controls)
{
//DO YOUR CHANGES
}
}
}

Related

How do I switch themes in Telerik WinForms?

How do I tell Telerik for WinForms which of its themes to use?
I created a new WinForms project and dropped a RadPageView on the form, but there's a 5-pixel margin of dead space all the way around, the tabs are almost twice as tall as they need to be, and everything is shiny and blue. Even apart from the wasted space, all this blue stuff would look horribly out of place in our app. I just want a standard Windows look, and I'm assuming that the way to accomplish that is to select a different, less-blue, less-shiny theme. (Or is there another way?)
Here's what I've tried:
I tried setting EnableTheming to False, but then the tabs have no borders at all, so there's absolutely no indication of where to click or which tab is active -- no good at all.
I can drop down the ThemeName property in the Property Grid, but the only options are "Reset" and "ControlDefault". Neither setting does anything (even with EnableTheming set back to True).
There are a bunch of Theme classes in the Toolbox (AquaTheme, BreezeTheme, etc.), but adding those to my form doesn't make any difference. I thought they might appear in the ThemeName dropdown, but they don't.
I tried dropping a RadThemeManager on my form, but it only has a LoadedThemes collection, which is empty. I can add things to it, but that just adds a ThemeSource, and setting one of those up seems to involve browsing to a file, and I don't have any theme files to browse to.
There's a ThemeClassName property on the RadPageView, but it's just a string (defaults to Telerik.WinControls.UI.RadPageView) and I have no idea what I might change it to, or how it even relates to themes.
This is ridiculous. All I want is a tab control that looks like a tab control! How can I do that?
The best way to accomplish this application-wide would be to use the ThemeResolutionService. You'll need to drag out one of the themes from the toolbox first. For example, if you add the Windows7Theme component to your form, you'd apply the theme using the following.
private void Form1_Load(object sender, EventArgs e)
{
ThemeResolutionService.ApplicationThemeName = "Windows7";
}
I recommend checking out this video related to themes as well:
http://tv.telerik.com/watch/winforms/visualstylebuilder/changing-themes-at-run-time-with-radcontrols-winforms
I'm currently working on a Winform/Telerik application.
It's a MDI application.
First, I added in the References of my Project the Telerik.Wincontrols.Themes.Breeze dll, then in the constructor of my main form, here is what I did :
private fMain()
{
InitializeComponent();
ThemeResolutionService.ApplicationThemeName = "Breeze";
RadGridLocalizationProvider.CurrentProvider = new FrenchRadGridLocalizationProvider();
}
I also added the French RadGridLocalizationProvider.
And it works, all my RadDataGridViews are in French and have the Breeze theme.
Even if the Form used is not a Telerik one, which is my case, I don't use RadForm !
To make loading of themes dynamic, I did following:
private void LoadTheme()
{
var themefiles = Directory.GetFiles(System.Windows.Forms.Application.StartupPath, "Telerik.WinControls.Themes.*.dll");
foreach (var theme in themefiles)
{
var themeAssembly = Assembly.LoadFile(theme);
var themeType = themeAssembly.GetTypes().Where(t => typeof(RadThemeComponentBase).IsAssignableFrom(t)).FirstOrDefault();
if (themeType != null)
{
RadThemeComponentBase themeObject = (RadThemeComponentBase)Activator.CreateInstance(themeType);
if (themeObject != null)
{
themeObject.Load();
}
}
}
var themeList = ThemeRepository.AvailableThemeNames.ToList();
themeDropDown.DataSource = themeList;
}
private void ThemeDropDown_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
string strTheme = themeDropDown.Text;
Theme theme = ThemeResolutionService.GetTheme(strTheme);
if (theme != null)
{
ThemeResolutionService.ApplicationThemeName = theme.Name;
}
}
I was able to achieve completely dynamic theme changing experience. In case Telerik release or updates themes in future, the only thing required will be to add the theme dlls in the application folder.

How can I find all controls within a control(WPF, C#)?

I found interesting questions about this like in How can I find WPF controls by name or type?, but I just want my method to return all controls within it. It doesn´t matter the control´s name or its type as long as the method returns all possible controls he can find.
In WinForms this is very easy ... just grab the WinForms container and then prob the '.Controls' property and iterate over the collection of controls returned.
foreach (System.Windows.Forms.Control ctrl in form.Controls)
{
if (ctrl.Name == "tabPageControl")
{ // do something with 'tabPageControl object' }
{
As you can see in WinForms its dead easy to get access at the global container to return a 'ControlCollection' and then iterate through or even deeper if its a panel or something like that. Once you have found what you want are simply building a list of what can be found then do something with your list or your control.
In WPF, this is done slightly differenty. I don't have extensive WPF experience but after 15 mins of playing about I came up with this:
private void button1_Click(object sender, RoutedEventArgs e)
{
// cast out Grid object.
Grid grd = (Grid) this.Content;
// do simple testing to find out what the type is.
string s = grd.ToString();
// in VS, in debug mode, hover 'grd.Children' and Smart Tool Tip that pops
// it will tell exactly under a 'count' property how many controls there are sitting
// on the global container. For me it was just 1, my Button.
foreach (UIElement child in grd.Children)
{
// do some more testing to make sure have got the right control. pref in an If statement but anyhooo.
String sss = child.GetType().FullName;
// cast out the appropriate type.
Button myWpfButton = (Button)child;
}
}
I hope thats enought to get you started.
It depends on the type of parent control. If it is an extension of ContentControl it can only have a single child element, which is found under the Content property.
If it is an extension of Panel it can have many child elements, which are found under the Children property.
There is no guarantee that any of those child elements are necessarily controls though - you will need to do some type checking to confirm whether or not they are of the type you are interested in.
This is also only for a single level of parent-child hierarchy, but should be simple enough to make recursive if you need all child controls.

Designing Windows.Form with multiple panels -> How to hide one panel (like a PS layer)

How can I hide one panel in Visual Studio 2008 Form Designer like a layer in PS? Otherwise, can someone recommend another better method to design multiple "screens" that must be clicked through by the user?
What you describe is a wizard, and you might want to investigate the approach from Eric J.
However, when I have cases where I want to have multiple panels in the same space within my UI and I want to switch between them in the designer, I like to use a TabControl and hide the tabs on the TabControl. This makes the UI easier to manage at design time and the code is pretty simple to switch between the tabs at run time.
I made a custom control that derives from TabControl called HiddenTabsControl that is very simple. The class only overrides the WndProc and lets the TabControl base class handle everything else. All you need to do is:
Add a New Item to your project
Choose Custom Control,
Name it something like HiddenTabsControl.
Change the base Class to TabControl, remove the Constructor and the OnPaint override that Visual Studio added.
Copy this override for WndProc into the class:
protected override void WndProc(ref Message m)
{
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328 && !DesignMode)
{
m.Result = (IntPtr)1;
}
else
{
base.WndProc(ref m);
}
}
Now you can change tabs in the designer and design the UI easily and in the code you can handle events to change tabs as needed. Changing the Selected tab is easily done with:
this.hiddenTabsControl.SelectedTab = this.tabPageYouWantVisible;
One side effect of removing the tabs is the space that the tabs occupy when the control is constructed. Removing them will make the space the HiddenTabsControl occupies change by shrinking it. I usually set the Anchor of the HiddenTabsControl to bottom to keep it from shrinking.
I used this Wizard code in a recent project and it worked well.
It provides the basic experience you are after.
Another less elegant, but quick hack, approach is to simply not add the panel to the parent form until runtime. In doing that, the designer has no idea where the panel belongs prior to compilation, and it won't be displayed.
For example, find the block of code where you add controls to the parent form:
//this->Controls->Add(this->panel_X);
this->Controls->Add(this->tabControl);
this->Controls->Add(this->menuStrip_topMenu);
Comment or remove the statement, then find the handle to the event that occurs when the form is loaded:
this->Load += gcnew System::EventHandler(this, &MainForm::MainForm_Load);
Then in the definition of the event handler, add the control to the form:
System::Void MainForm_Load(System::Object^ sender, System::EventArgs^ e) {
...
...
this->Controls->Add(this->panel_X);
}
I haven't experienced any unwanted side effects by doing this, but if anyone has a good reason to not I'd be interested in hearing it.

WPF windows organization techniques

Im developing some wpf app. Basically i have two types of windows: search windows and insert/edit windows. When i developed win forms apps, i used a trick, called MdiParent. In that way i had ability to put my caled search type windows in a "stack". In orher words if i called 5 different search windows from meniu, they apeared in a component like tab control, one after other.By clicking on that tabs, i could see search results of clicked tab window. The trick as i said was MdiParent technique, like:
private ProductDiscount frmProductDiscount = null;
private void ProductDiscountToolStripMenuItem_Click(object sender, EventArgs e)
{
if ((frmProductDiscount == null) || (!frmProductDiscount.Visible))
{
frmProductDiscount = new ProductDiscount();
frmProductDiscount.MdiParent = this;
frmProductDiscount.Show();
}
else
{
frmProductDiscount.Activate();
}
}
So does anyone can me suggest a good way to implement such a window organization technique in WPF and put some links or examples..?That would be a big help for me.
There is no equivalent of Form.MDIParent in WPF and MDI does not support the idea of an MDI layout. You can set a Windows Owner to another window. This will minimise the child when the parent is minimised.
For an example of MDI style functionality have a look at this thread link text
where Marlon Grech has written something similar to what I believe you are trying to do.
We developped similar application, as WPF doesnt have any default MDI framework but since its completely customizable, what you can do is, you can create User Controls of your "Window" instead of Window type and you can use inside a TabControl and you can customize TabControl to have close buttons etc. Windows in Tabs as they appear in Visual Studio, IE etc, they work good for this type of scenario when you dont want to block user input on modal dialog.

How do I hide the input caret in a System.Windows.Forms.TextBox?

I need to display a variable-length message and allow the text to be selectable. I have made the TextBox ReadOnly which does not allow the text to be edited, but the input caret is still shown.
The blinking input caret is confusing. How do I hide it?
You can do through a win32 call
[DllImport("user32.dll")]
static extern bool HideCaret(IntPtr hWnd);
public void HideCaret()
{
HideCaret(someTextBox.Handle);
}
When using the win32 call don't forget to hide the cursor in the textbox's GotFocus event.
Just for completeness, I needed such a functionality for using with a DevExpress WinForms TextEdit control.
They already do provide a ShowCaret and a HideCaret method, unfortunately they are protected. Therefore I created a derived class that provides the functionality. Here is the full code:
public class MyTextEdit : TextEdit
{
private bool _wantHideCaret;
public void DoHideCaret()
{
HideCaret();
_wantHideCaret = true;
}
public void DoShowCaret()
{
ShowCaret();
_wantHideCaret = false;
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
if (_wantHideCaret)
{
HideCaret();
}
}
}
To use the code, simply use the derived class instead of the original TextEdit class in your code and call DoHideCaret() anywhere, e.g. in the constructor of your form that contains the text edit control.
Maybe this is helpful to someone in the future.
If you disable the text box (set Enable=false), the text in it is still scrollable and selectable. If you don't like the visual presentation of a disabled text box (gray background usually) you can manually override the colors.
Be warned, manually overriding colors is going to make your form/control look weird on systems that do not use the default color/theme settings. Don't assume that because your control is white that everyone's control is going to be white. That's why you should always use the system colors whenever possible (defined in the System.Drawing.SystemColors enumeration) such as SystemColors.ControlLight.
I know this is an old thread but it is a useful reference.
I solved the problem with a much easier but very kludgie solution, which may depend on how much control you have over the user's access to the form. I added a textbox (any focus-able control) which I gave prime tabIndex value and then positioned it off-form so that it was not visible. This works fine on a dialog because the user can't resize. If the form is resizeable, this may not work.
As I said, a kludge - but a lot easier to set up. (BTW I found the HideCaret approach didn't work - but I didn't pursue it hard.)
AFAIK, this cannot be done. The TextBox control is a funny control because it actually has a lot of behaviour that can't be modified due to the way it taps into the operating system. This is why many of the cool custom TextBoxes are written from scratch.
I am afraid you may not be able to do what you wish to do :(

Resources