UserControl - Show properties of inner-control in design-mode properties windows - properties

I got a UserControl name UC1, which contain 2 controls (textbox, label). after that i create new windows form and drag the UC1 to it, how can i read and write ALL properties of textbox and label (inside UC1) in "Properties Windows" in design-mode? currently, i only can see UC1's properties, but properties of textbox and label never show out. please ... thanks..
REMARKS: No want create 1 by 1 of properties of control for example: Public Overrides Property blabla As String... End Property

in control.cs
[Description("Label displayed in the Control"), Category("Controls")]
public Label lblCaption
{
get { return _lblCaption; }
set { _lblCaption = value; }
}
in control.Designer.cs
public System.Windows.Forms.Label _lblCaption;
do this for button

Related

Cannot get the selected item in a ListViewer in a JFace Dialog

I created a dialog class that inherited from JFace Dialog using Windows Builder. In that, I added some controls included a button and a JFace ListViewer. In widgetSelected() function of the button, I can get out the selected item in the ListViewer. But in `okPressed(), I cannot get this. I don't know why. Can you help me?
Thanks!
If you want to access UI elements in okPressed you must do so before calling super.okPressed() because that will close the dialog and dispose of the controls. So something like:
#Override
protected void okPressed()
{
IStructuredSelection sel = viewer.getStructuredSelection();
// TODO deal with selection
// Call super.okPressed() last
super.okPressed();
}
Alternatively save the selection when your widgetSelected is called.

VB.NET never get focus on any control

i have developed a simple calculator like in windows calculator,
but unlike in windows calculator, after clicking any button, the focus on that button is still there on the particular clicked button.
so how to never get focus for all buttons on calculator form ... ?
i don't think that it will better to write loose focus code on every button's click event ... so any better solution ?
Without seeing any code of yours, I am going to assume that you have a text box that displays the numbers pressed by the user, so you need to set the focus to the text box once a user clicks a button, like this:
TextBox1.Focus()
Note: If your text box is not named TextBox1, then change the name to whatever your text box is actually named.
Instead of a standard button use an instance of a NoFocusButton class derived from the Standard button. In this class override the ShowFocusCues property and return always false.
Form f = new Form();
// Need to add manually the buttons to your form unless you build a customcontrol
NoFocusButton b = new NoFocusButton();
b.Text = "ClickMe";
f.Controls.Add(b);
f.Show();
// Class derived by the Button control, it is identical but the
// property that control the drawing of the Focus rectangle returns FALSE
// tricking the WinForm system to avoid to draw the focus rectangle
class NoFocusButton : System.Windows.Forms.Button
{
protected override bool ShowFocusCues
{
get
{
return false;
}
}
}
The credit goes to Remove Focus Rectangle from Button

How to bind event in the style in Silverlight 4

I have a control where is about 100 hundred TextBoxes, and I need for each of them have binded event to GotFocus event (where I select all text).
I cant use EventSetter as in WPF, so what do you use to bind event in style?
You'll have to subclass the TextBox class and then use that in all your code.
You can then put the GotFocus event handler in that subclass, otherwise you'd have to add the GotFocus event handler to all your code.
public class MyTextBox : TextBox
{
protected override void OnGotFocus(RoutedEventArgs e)
{
// Add your code in here
base.OnGotFocus(e);
}
}
Then in your XAML you'd have:
<my:MyTextBox ..... />

How to set customized tabstop color for a button in vb.net

I have placed a background image on my windows application form and when tab stops to a particular button it's color is changed and looks awkward...Can anyone tell me that how can I set some customized color for tabstop or set its value to null????
I've tried the answer from BalaR i.e. button.ShowFocusCues = falase in load event of the form but it says that it can't be used like this and it is protected
try ShowFocusCues to false
button.ShowFocusCues = false;
to hide focus rectangle.
I didn't notice it was a protected member. You have two options
use reflection to set the protected member (not recommended)
create a derived class and set the protected member as you'd like. (the right way)
class MyButton : Button
{
protected override bool ShowFocusCues
{
get { return false; }
}
}
You can also set TabStop to false.
button.TabStop = false;
if you don't want the button to obtain focus during tab cycle.

ToolStripButton = "Pressed"

I got a toolstripbutton, and when I click it, I want to make it stay "pressed" or "selected". Like a switch. And when I click another, make the pressed one "unpressed" again. Any ideas?
I think you want to use the CheckOnClick property. Set it to true, and the button should behave as you describe. In order to get (or set) the current state, use the Checked property.
Here is a full working sample:
public partial class Form1 : Form
{
private readonly IEnumerable<ToolStripButton> mutuallyExclusiveButtons;
public Form1()
{
InitializeComponent();
mutuallyExclusiveButtons = new[] { firstButton, secondButton };
}
private void ToolStripButton_Click(object sender, EventArgs e)
{
ToolStripButton button = sender as ToolStripButton;
if (button != null && button.Checked &&
mutuallyExclusiveButtons.Contains(button))
{
foreach (ToolStripButton item in mutuallyExclusiveButtons)
{
if (item != button) item.Checked = !button.Checked;
}
}
}
}
firstButton and secondButton are ToolStripButtons, both have CheckOnClick set to true, and their Clicked events hooked up to ToolStripButton_Click. This works also if there are more than two buttons in the group of buttons in which only one should be checked, just add any needed additional buttons to the mutuallyExclusiveButtons sequence.
As ChrisF said, what you are looking for is the "Checked" property. (The "CheckOnClick" property is actually not what you want, since you want a sort of mutually exclusive toggle between two ToolStripButtons.)
What you will need is to put code (into the click event of each button) that will set the Checked property of that button to True and the Checked property of the other button to False.
Actually, you can use CheckOnClick and then add code only to set the other button to False.
(Hmmm... I wonder when the Checked becomes set to True; can you capture the MouseUp etc. event of BOTH buttons into one handler, and uncheck BOTH buttons, and then CheckOnClick will check the appropriate one later? Just some geek stuff to complicate things unnecessarily in the name of simplifying things)
Maintain a flag as to what the status of a button is (pressed or normal). For each button press, call a method that refreshes the toolbar buttons to the correct state (either stay pressed or go back to normal).