Show Control.Text in VisualStudio Designer - visual-studio

I'm using VisualStudio 2005 and I want to set the text of a control on a form. For various reasons this should not be done in the VisualStudio Designer. I could write the code as follows:
public Form1( )
{
InitializeComponent( );
button1.Text = "Test";
}
But now I don't see the text in the designer, the button is empty (or has the default text of "button1"). Is there a way to set the text of a control outside the designer and see the text in Visual Studio Designer? The text should not be editable, it must only be visible. This would be really nice, because it would be possible to use constants for frequently used phrases and still see them in the designer to adjust the ui.

It's a bit hacky, but you could subclass the control you want and override the Text property:
public class MyTest : Button
{
public override string Text
{
get
{
return #"test";
}
set
{
}
}
}
This shows up in the designer, but when you try and change it Visual Studio just ignores you. You probably want to do something other than just return a hardcoded string literal, but I'm sure you get the idea :-)

Related

VisualStudio customize paste operation for my component at design-time

I created WinForm component and I want to replace some properties of my component when developer copy and then paste(not when copy but when paste) component from clipboard at design time.
VisualStudio creates new copy of component and assign properties so it became copy of the source component.
I need to replace some properties on paste operation depending on the selected component.
It is very similar to standard Copy/Paste operation with Control component. When designer change Parent of component if developer select other container (like Panel) before Paste Control.
I think that code to perform it should be somewhere in my ComponentDesigner class.
I explored ComponentDesigner methods but can't find any methods that controls clipboard operations.
You can override the OnParentChanged method of your component, which is executed when the component is pasted onto the form. Then test the DesignMode property to make sure you are in design mode:
public class MyComponent : Label
{
protected override void OnParentChanged(EventArgs e)
{
if (DesignMode) {
// Change properties as desired.
Text = "Design";
}
base.OnParentChanged(e);
}
}
When the component is dropped from the Toolbox, this code is not executed. (I can't explain why, but it happens to be exactly what we need.)
If you derived your component from System.ComponentModel.Component, you can override the property Site; however, this will require some more logic to check whether the component has been pasted.
public override ISite Site
{
get {
return base.Site;
}
set {
base.Site = value;
if (value?.Container is IDesignerHost dh &&
dh.TransactionDescription == "Paste components") {
MessageBox.Show("Pasted");
}
}
}
But probably the transaction description is localized, because it is the text that you see in the drop-down of the Undo button on the toolbar of Visual Studio after having pasted the component.

Change icon on button in scout eclipse

I would like to implement some think like toggle button in scout eclipse.
What I need is to change image of button for state.
I see function
setIconId(String)
but I dont know how to find parameter for this function. How to find image that scout use for different state of button?
Marko
setIconId(..) and Icons
It is a good practice in your Scout Application to pass as Argument from setIconId(..) a constant defined in the Icons Class. See Icons page on the wiki.
An example for your use case:
setIconId(Icons.WeatherSun)
In the Demo Widget Application there is an Icons class:
org.eclipsescout.demo.widgets.shared.Icons
Here some constants defined in this class:
public static final String WeatherRain = "weather_rain";
public static final String WeatherSnow = "weather_snow";
public static final String WeatherSun = "weather_sun";
The values defined in the constants represent an identifier for the image.
The Image lookup is realized by the ImageLocator. (Depending on the UI technology, the appropriate IconLocator will be used. For example, in case of Swing the SwingIconLocator implementation).
In case of weather_sun the default implementation of the ImageLocator will look for a File called weather_sun.<ext> (where <ext> can be gif, png and so on) in the \resources\icons\ folder of each plugins. In this case it will find the File: \org.eclipsescout.demo.widgets.client\resources\icons\weather_sun.png
If the image is not found, you will see a log entry like this:
!MESSAGE org.eclipse.scout.rt.ui.swing.SwingIconLocator.warnImageNotFound(SwingIconLocator.java:141) could not find image 'weather_sun'
In the Scout SDK, there is an Icons Editor. This Editor represents all the constants defined in the Icons class and the corresponding Icon. Is a file not found a red square is displayed instead of the image.
Toggle Button
There is no specific field for Toggle Button, use an AbstractButton an set the display style to DISPLAY_STYLE_TOGGLE.
See also:
10.8 - Buttons and Links in the Scout Boook.
ToggleButton wiki page.
Changing the icon in a Toogle Button
I think this code snippet does what you are looking for:
#Order(10)
public class ToggleButton1 extends AbstractButton {
#Override
protected boolean getConfiguredProcessButton() {
return false;
}
#Override
protected void execClickAction() throws ProcessingException {
if (isSelected()) {
setIconId(Icons.WeatherSun);
}
else {
setIconId(Icons.WeatherRain);
}
}
}
It would also be possible (and even better) to use execToggleAction instead of execClickAction.
Screenshot:

WP7 - how to let user set app theme

My app has 10 pages and all of them have black background. I want to let user change background color of all pages using radioButton in my app. How can I do this in easiest way?
Go through these blogs
1. Theme Forcing for Windows Phone 7 or,
2. Windows Phone Mango Custom application Theme
these might prove helpful to you. You can study these and modify to put them in your settings page.
Thank You :)
Ok so you have 10 pages and on each page you want to change the background colour of those pages through the settings menu. What you can do is use the Windows Phone IsolatedStorageSettings.
Firstly you want to initialize the IsolatedStorageSettings. You can do that like this:
IsolatedStorageSettings MyAppSettings = IsolatedStorageSettings.ApplicationSettings;
Then you will have to set a default value for it so it doesn't throw an exception. You can do this:
MyAppSettings.Add("PageBackgroundColor", "#000000"); // you can set whatever the default colour you want here. i.e. Black
the best place i think would be is to add this code in:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("PageBackgroundColor"))
{
// Don't do anything because you've already set the default background colour for the pages
}
else
{
// add the default color
}
}
Now in your MainPage you can reinitialize the IsolatedStorageSettings. Once you've done that you will want to get the value of the setting and depending on the value you will want to change the background color. To read the value:
string Sortval = (string)MyAppSettings["PageBackgroundColor"];
You can add this in the:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
Or
public MainPage
{
InitializeComponent();
}
Remember that public MainPage will only run once and the OnNavigatedTo runs every time the page is loaded so if you want to update the background color right after adding the setting, OnNavigatedTo is the way to go but if you want to apply the changes after a restart, public Mainpage is it.
Now to read the value and change it you want to do something like:
string val = (string)MyAppSettings["PageBackgroundColor"];
if (val == "#000000")
{
//change to black
}
else if (val == "your hex color")
{
//change to whatever color
}
else if (val == "another hex color")
{
//...
}
Now to save the value you want to reinitialize the IsolatedStorageSettings in your settings page and to save the values it would be something like this:
MyAppSettings.Remove("PageBackgroundColor");
MyAppSettings.Add("PageBackgroundColor", "your hex color");
MyAppSettings.Save();
This is untested however It should give you the very basic idea on how to do it in terms of saving and loading setting and then applying it

Replacing texts "OK", "Cancel", "Apply" and "Help" in Win32 property sheets

On a Win32 property sheet the texts "OK", "Cancel", "Apply" and "Help" are automatically displayed in the system's language. That can be a problem if the language of a Software is different of the system's language.
For instance if a customer installs the French version of our software on an English Windows, the property sheet's content will be in French but the standard buttons at the bottom of the property sheet will be in English not matter what.
Does anybody know how can I change these texts.
Actually changing these texts is quite simple. The only thing that must be done is to derive a class from CPropertySheet, override the OnInitDialog method and change the texts in the overridden OnInitDialog.
class CMyPropertySheet : public CPropertySheet
{
public :
CMyPropertySheet() ;
protected:
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
} ;
BOOL CMyPropertySheet::OnInitDialog()
{
...
SetDlgItemText(IDOK, whatever..) ;
SetDlgItemText(0x3021, whatever..) ; // 0x3021 == IDAPPLY
SetDlgItemText(IDCANCEL, whatever...) ;
SetDlgItemText(IDHELP, whatever...) ;
}

Creating Dialogs with Silverlight Prism

I'm new to creating Silverlight applications. I have inherited a code-base that I've been told is using Prism. Based upon what I've seen in the code-base, this looks to be true. My problem is, I am just trying to open a dialog window and close a dialog window.
To open the dialog window, I'm using the following:
UserControl myDialog = new MyDialog();
IRegion region = myRegionManager.Regions["DIALOG_AREA"];
IRegionManager popupRegionManager = region.Add(myDialog, null, true);
region.Activate(myDialog);
The dialog I have designed appears. It has two buttons: "OK" and "Cancel". When a user clicks on of these dialogs, I want to close the dialog. My problem is, I have no idea how to do this. Because the dialog is not a ChildWindow, I cannot call this.Close(). But, when I change MyDialog to a ChildWindow, it is wrapped in some custom window chrome that i can't figure out how to get rid of.
How do I close a dialog in Prism? Thank you!
Instead of putting in a different region, you should make your ViewModel call a service where you call your dialog window.
public MainPageViewModel(IMainPage view,
ILoginBox loginBox )
: base(view)
{
this.view = view;
this.loginBox = loginBox;
}
public interface ILoginBox
{
void Show();
}
remember to use the IOC container and declare on your ModuleClass:
protected override void RegierTypes()
{
base.Container.RegisterType<ILoginBox , LoginBox>();
}
I hope it helps.
If you are still looking for an example, check:
another Stackoverflow sample

Resources