C# Winforms Devexpress has other button tooltips? - c#

In normal Winforms I have a maximize button with standard tooltips on mouse move.
Within devexpress my maximized button show after maximized "Restore Down" and in german "Wieder nach unten". It is bad, because not like the windows standard. I cannot change the tooltip, because I donĀ“t know how to access the maximize button of the form.
Language: C#, Winforms
WIth UI Lib: Devexpress
Can someone help me?

You can create your own Localizer class that inherits from DevExpress.XtraBars.Localization.BarLocalizer. Override the GetLocalizedString method and return what value you'd like for the minimize/maximize buttons. For instance:
public class MyRibbonLocalizer : DevExpress.XtraBars.Localization.BarLocalizer
{
public override string Language
{
get
{
return System.Globalization.CultureInfo.CurrentCulture.Name;
}
}
public override string GetLocalizedString(BarString id)
{
switch (id)
{
case BarString.MinimizeButton:
return "My Minimize string";
case BarString.MaximizeButton:
return "My Maximize string";
default:
return base.GetLocalizedString(id);
}
}
}
You will need to register this localizer class in your RibbonForm in order for it to work. I typically do this within the constructor:
DevExpress.XtraBars.Localization.BarLocalizer.Active = new MyRibbonLocalizer();

Related

Windows Forms - ErrorProvider overlapping icons

I'm using a custom icon in my ErrorProvider with
ErrorProvider.BlinkStyle = ErrorBlinkStyle.NeverBlink
I've got a problem with overlapping icons using code that is similar to this one:
public partial class TestForm : Form
{
private ErrorProvider _errorProvider1;
private ErrorProvider _errorProvider2;
private CheckBox _control1;
private CheckBox _control2;
//...
private void ValidateAll()
{
_errorProvider1.Clear();
_errorProvider2.Clear();
_errorProvider1.SetError(_control1, string.Empty);
_errorProvider2.SetError(_control2, string.Empty);
if(Validate(_control1.Checked))
{
_errorProvider1.SetError(_control1, "Error1");
}
if(Validate(_control2.Checked))
{
_errorProvider2.SetError(_control2, "Error2");
}
}
//...
}
I'm interacting with _control1 while _control2 has some error (is Checked), thus _errorProvider2 has some error set. Everytime method ValidateAll is called it will correctly set _errorProvider1 for _control1 but _control2 _errorProvider2 will keep drawing extra icons without erasing old ones.
Starting view
After 'clicking' _control1 multiple times
When interacting with _control2, _errorProvider2 will go back to normal, but _control1's _errorProvider1 will do the same until it is 'clicked'.
After 'clicking' _control2
Please note that underlying Control doesn't affect it; it doesn't have to be CheckBox.
What I tried:
Using only one ErrorProvider per Form/Control,
Focusing each Control before setting ErrorProvider,
Not clearing ErrorProviders
Any help is much appreciated, thanks!

Creating a windowless menu-bar icon application in Monomac/Xamarin C#

I am attempting to create an application in MonoMac/Xamarin.Mac that does not have a dock icon, nor a visible window when it launches and only an icon in the top-right menu bar.
I have set LSUIElement = 1 (tried both String and Boolean types) in Info.plist, but the status menu icon isn't displayed at all when the application launches. The only way I can get it to appear is by removing the LSUIElement flag, although then the dock icon becomes visible.
The snippet I am using is:
public partial class AppDelegate : NSApplicationDelegate
{
public AppDelegate ()
{
}
public override void FinishedLaunching (NSObject notification)
{
// Construct menu that will be displayed when tray icon is clicked
var notifyMenu = new NSMenu();
var exitMenuItem = new NSMenuItem("Quit",
(a,b) => { System.Environment.Exit(0); }); // Just add 'Quit' command
notifyMenu.AddItem(exitMenuItem);
// Display tray icon in upper-right-hand corner of the screen
var sItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
sItem.Menu = notifyMenu;
sItem.Image = NSImage.FromStream(System.IO.File.OpenRead(
NSBundle.MainBundle.ResourcePath + #"/menu_connected.png"));
sItem.HighlightMode = true;
// Remove the system tray icon from upper-right hand corner of the screen
// (works without adjusting the LSUIElement setting in Info.plist)
NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Accessory;
}
}
Does anyone know of a good way of creating a windowless application in MonoMac that doesn't have a dock icon and only a menu bar icon?
Thanks,
BB
Try specifying a .xib for the "Main nib file name'
I did this some time ago, and it works fine for me. Something like this:
New monomac project
Created an 'AppController' class in C#:
[Register("AppController")]
public partial class AppController : NSObject
{
public AppController()
{
}
public override void AwakeFromNib()
{
var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
statusItem.Menu = statusMenu;
statusItem.Image = NSImage.ImageNamed("f3bfd_Untitled-thumb");
statusItem.HighlightMode = true;
}
In MainMenu.xib, I deleted the application menu
In MainMenu.xib, I added an custom object and set it's type to AppController
I created my status menu in the .xib and then connected it to the AppController with an outlet
In info.plist, I add the "Application is agent (UIElement)" value as a string and set it to "1"
Try it out with a .xib. If it doesn't work, maybe I can share my project for you to take apart.

How to add customized component in C#?

I need to call acadcolor component from visual studio.when i add the component it's fine.
After I need to use that component so just I drag and drop that control to windows form visual studio automatically closed without passed any message.
Can anybody know how to add and how to work with acadcolor component from visual studio?
Thanks advance.
Here's an ADN article on just what Alex Filipovici was mentioning:
Use 64-bit ActiveX Component from a .NET Assembly
There are other alternatives too. Here's an ADN article replicating the control with WPF: WPF Implementation To Mimic Color Layer Controls.
You can also open the color dialog if it's to select a color. That's what I've done most recently:
using acColor = Autodesk.AutoCAD.Colors;
using acWindows = Autodesk.AutoCAD.Windows;
//...
public acColor.Color GetAutoCADColor()
{
acWindows.ColorDialog colorDialog = new acWindows.ColorDialog();
DialogResult dialogResult = new DialogResult();
dialogResult = colorDialog.ShowDialog();
switch (dialogResult)
{
case DialogResult.OK:
return colorDialog.Color;
case DialogResult.Cancel:
return Color.Empty.ConvertToAutoCADColor();
default:
return Color.Empty.ConvertToAutoCADColor();
}
}
Extension methods:
internal static class ColorExtensions
{
internal static Color ConvertToWindowsColor(this acColor.Color acColor)
{
return Color.FromArgb(acColor.ColorValue.ToArgb());
}
internal static acColor.Color ConvertToAutoCADColor(this Color winColor)
{
return acColor.Color.FromRgb(winColor.R, winColor.G, winColor.B);
}
}
Just a thought or two.

C# Drop Down menu with labels in Winforms

I would like to have a drop down menu in Winforms in C# with Text Label in between the menu items. It will be very similar to seperators. So basically I am looking at an option of grouping the menu items.
Any idea how we can achieve it ? Attached is the drop-down menu I wish to have.
Hope you are using VS2010
In the Menu Designer, right-click the location where you want a separator bar, and choose Convert To -> Separator.
MSDN Article on menu enhancements
You might want take a look at this also (Its about form separators, but version is VS2003!) -- Windows Forms Separator Control
May be below link can help you:
A Seperator Combo List Vox
I'm sure there are many complex ways to do this but i've found one that might satisfy your needs in 3 Steps:
1.You make your own ToolStripItem:
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All)]
public sealed class CustomToolStripMenuItem : ToolStripMenuItem
{
public CustomToolStripMenuItem()
{
DisplayStyle = ToolStripItemDisplayStyle.Text;
BackColor = Color.LightSteelBlue;
ForeColor = Color.MidnightBlue;
Font = new Font(Font, FontStyle.Bold);
// Or other options to your liking
}
}
2.You make your own Renderer:
public class CustomeRenderer : ToolStripProfessionalRenderer
{
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
{
if(e.Item is CustomToolStripMenuItem)
{
e.Graphics.FillRectangle(Brushes.LightSteelBlue, e.Item.ContentRectangle);
}
else
{
base.OnRenderMenuItemBackground(e);
}
}
}
3.Use your items:
For your contextmenu you need to set up the renderer:
RenderMode = ToolStripRenderMode.Professional;
Renderer = new CustomeRenderer();
In your context menu you can now use your CustomToolStripMenuItem

How to capture selected values from a dialog?

I created a FontDialog.cs Windows Form where my users can choose colors among other things for the text. I need to capture what the user has selected on the dialog:
Here's how I'm calling the dialog:
DialogsTestingGrounds.FontDialog dialog = new FontDialog();
dialog.ShowDialog();
How can I capture the selected values, I imagine I have to create properties for everything I want to transfer on the FontDialog.cs form end, right?
What you would want to do is expose properties on your FontDialog that make the values available. You could then use dialog.PropertyName to reference it by the name of the property.
It is not necessary, you can use, ie, dialog.Font to get the selected font,
dialog.Color for the color and so on...
Mitchel's answer will work but you might want to incorporate a couple other items along the same line.
Have a public property (per Mitchel's
answer).
Have a public constructor on your
form with the type of the property as
an argument so you can pass in the value
in question (this would allow you have the dialog prepopulated with old selection).
Surround your call to your dialog
with a check for dialogresult so you
only change the value when the user
wants to. (note the process for this is different in WPF)
Felice is also right in that you
don't really need to create a new
font dialog if the only thing you
care about is the font. There is a
built in font dialog in .Net
http://msdn.microsoft.com/en-us/library/system.windows.forms.fontdialog%28v=vs.71%29.aspx
So the internals of your dialog class may look like this psuedo code.
public Font SelectedFont { get; set; }
public FontDialog()
{
//set your defaults here
}
public FontDialog (Font font)
{
SelectedFont = font;
//dont forget to set the passed in font to your ui values here
}
private void acceptButton_Click(object sender, EventArgs e)
{
SelectedFont = //How ever you create your font object;
}
Then to call your function (assumes the the acceptButton above is the forms AcceptButton)
DialogsTestingGrounds.FontDialog dialog = new FontDialog();
if(dialog.ShowDialog() == DialogResult.OK)
//Do Something

Categories

Resources