Help hint creation in C# WinForms - c#

Image http://www.freeimagehosting.net/uploads/7efc3b2ddd.png
Is there any idea to create this in C# Windows Application.

We have a tool tip property of Text Box.Select the Text box press F4 or directly go to the property of Text box->Tool Tip->(Put the Text Whatever you want)This value can't be blank.

There is an "Error Provider" component that you can add to a form, which adds a "Error" property on every control. It accomplishes a similar goal, but does it a bit differently as far as the visual representation goes.

Propably you need validators to check input forms. these classes are presented in ASP.NET
unfortunatly for winforms you should do it on your own.
for instance there are events of TextBox Validated and Validating what you can handle to check input data.

Can't we use like
ToolTip t = new ToolTip();
t.IsBalloon = true;
if(textBox1.Text=="")
t.Show("This value can not be empty", this.textBox1 , 0, -40, 1000);
??

Related

Coded UI tests not correctly finding my control

I'm busy running a proof of concept on what should be a very basic coded UI test.
My application is Winforms, I have a form that allows you to log in to the application.
Here 2 controls exist called _textUsername and _textPassword respectively.
To simplify the whole thing, I want playback to be able to double click the username text field (_textUsername).
However, during playback the _textPassword is selected.
I've tried to adjust the search criteria to include the control name , but then it fails to find the control at all and fails.
My question is simple: I have 2 controls on my form : _textUsername and _textPassword, UI coded tests seems to always find the _textPassword, how can I get it to find the other text box instead?
Try manually coding the controls. You can use the UI Test Builder to find the search properties. inspect.exe is also useful. Sometimes the properties aren't what you expect.
// Controls
WinWindow logonWindow = new WinWindow();
WinEdit _textPassword = new WinEdit(logonWindow);
WinEdit _textUsername = new WinEdit(logonWindow);
// Add search properties and configurations
logonWindow.SearchProperties[WinWindow.PropertyNames.Name] = "Main Window Name";
logonWindow.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
_textPassword.SearchProperties[WinEdit.PropertyNames.Name] = "Password";
_textPassword.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
_textUsername.SearchProperties[WinEdit.PropertyNames.Name] = "Username";
_textUsername.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
// Identify each control
logonWindow.DrawHighlight();
_textPassword.DrawHighlight();
_textUsername.DrawHighlight();
This turned out to be wrong versions in DevExpress between the client application and the test runner code.

The header text in MessageBox.Show() is trimmed

I'm using MessageBox.Show() in a console application for a purpose. But, the header text displayed in the MessageBox is trimmed as it displays ending characters as "...".
Can I set the MessageBox window width to handle this behavior.
Please help me in this regard.
Thanks in advance.
No, in the default MessageBox its not possible to change the size of it. But if you want it, you can create your own message box. Just create a new form, put some buttons inside, in icon if you wanto and some text. And when you want it to show, just simply call ut, like you open the form
See
here
C# formatting a MessageBox
It can't be done. You have to create your own Form mimicking that behavior.
You can try to use the Win32 call SetWindowPos As suggested here.

Find if TextBox.Text got changed by the user or by the code (Windows Phone 8)

I have a Windows Phone 8 project that converts values (i.e.: Celsius to Fahrenheit). There are two TextBox UI elements, one of which is read-only. The user can change the first TextBox to input the value to be converted. He can also press a button to "swap" the two TextBoxes so that he can do the reverse conversion. When the user presses the button, the value from the second TextBox goes into the first TextBox (and vice versa). But it's not the user who changed the value, it's the code who did.
I asked around (on IRC) and researched the subject, but I am a beginner and couldn't understand most of what I have found.
I heard that a simple solution would be to use Data Bindings. I researched the subject, and from what I read, Data Bindings can't solve my problem (correct me if I'm wrong).
I also tried to create a subclass of TextBox, hoping that I could hook in some custom event to it and go further in that direction. But I did not understand how to link the custom TextBox to the UI (in XAML). The way I created the subclass is to just create a new class and add TextBox as the parent. I know there is a template in VS to create a new User Control, and I tried it, but I couldn't understand what I was doing (or what I was supposed to do).
So I have two questions: Am I looking at the problem from the right angle? If yes, how do I create a custom TextBox and link it to the UI? If not, how could I solve my problem?
If your question is how to distinguish if the text got changed by the user or by the code then its simple.
Assuming that when the user types something you'd like to perform method A but when the code changes the text you'd like to perform method B:
In both cases you will need to override the TextBox.TextChanged() event handler.
You will also need a flag variable to tell you if the swap button was pressed or not.
The event handler should be something like this:
{
if (swap_pushed)
{
Method_B();
swap_pushed = false;
}
else
{
Method_A();
}
}
And finally your event handler for swap Button.Click() should be like this:
{
swap_pushed = true;
}

how to display textBox control in MessageBox?

Any idea how to display textBox control in MessageBox.
I'm working on winforms projcet c#.
Thank you in advance.
You can't. MessageBox is a special container designed to only show a message and buttons. Instead, you can create your own Form with whatever controls you want, and use .ShowDialog() on it.
You can simply add an Input box from VB.NET into your C# project.
First add Microsoft.VisualBasic to your project References, then use the following code:
string UserAnswer = Microsoft.VisualBasic.Interaction.InputBox("Your Message ", "Title", "Default Response");
And that should work properly.
It will be better to add a new Form in you application which you can customize the way you want.
and just call it from where ever required.
you could create a classic win form that looks like a message box and opening it as a modal form
perhaps using Form.ShowDialog
more info at
http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx
You cannot customise the MessageBox, its better you use a popup designed using Windows Form separately and use its instance to invoke.
customPopup popup = new customPopup();
popup.ShowDialog();
Place your controls on the popup form and set their access modifiers to public if you want to access the textboxes or labels etc in your previous form.
customPopup popup = new customPopup();
popup.msgLabel.Text= "Your message";
popup.ShowDialog();
As I know there is no way to do that.
You can create a winform change it's style to look like a MessageBox and add your own controls.
Yes, as krillgar mentioned,you should create your own form. And
1. Encapsulate the form in a static class or function, so you may just call MyMessageBox.Show().
2. The textbox should have readonly=true, so the end users won't be able to change the text displayed, while they could select text and copy to clipboard.
Regarding to item 2, I believe many Windows build applications and MS Office use such approach.
using Microsoft.VisualBasic;//add reference
var Password = Interaction.InputBox("Message", "Title" ,"information in textbox", -1,-1);
In the variable "password" it receives the information that is entered from the text box.
Remember to add the reference "Microsoft.VisualBasic" in the solution explorer
Solution in here, you can create windows form and design it, set form is dialog, when you call form, it is auto show. In form you design, you set value some parameter static where other class in project, but you should set when you close form design that, OK, come back form init call show dialog, you create interval call when have == null return call, when != null you stop call back and using parameter in class static it !

Using F1 Help (CHM format) With WPF

I've been working on a WPF application for a while, and the time has come to attach the CHM format help document to it.
But alas! HelpProvider, the standard way to show CHM files in Winforms, has magically vanished and has no counterpart in WPF. I've been trying to use WindowsFormsHost to spawn a new control so I can actually display the help, but essentially it just grabs control of the entire UI.
A little more detail: I've got a menu item that I want to, when clicked, open up the CHM file.
First I set up the WindowsFormsHost...
host = new System.Windows.Forms.Integration.WindowsFormsHost();
helpForm = new System.Windows.Forms.Control();
host.Child = helpForm;
host.Visibility = System.Windows.Visibility.Hidden;
this.grid1.Children.Add(host);
hp = new System.Windows.Forms.HelpProvider();
hp.HelpNamespace = "Somehelpfile.chm";
hp.SetHelpNavigator(helpForm, System.Windows.Forms.HelpNavigator.TableOfContents);
And then I say, voila, reveal yourself.
private void Help_Click(object sender, RoutedEventArgs e)
{
host.Visibility = Visibility.Visible;
helpForm.Show();
hp.SetShowHelp(helpForm, true);
}
I'm not really sure of where to proceed from here. When I show the helpForm, it obscures / overrides the existing UI and all I get is a gray, empty WPF window with no help file.
Any takers?
If you include System.Windows.Forms.dll you can also do:
System.Windows.Forms.Help.ShowHelp(null, #"help.chm");
Also, there's an article here about adding a context sensitive help system to WPF.
Call me crazy, but couldn't you just do:
System.Diagnostics.Process.Start(#"C:\path-to-chm-file.chm");
I am trying out Easy Help with WPF, which also addresses context sensitive help based on key words. So far it seems good. All I need to do is get cracking and write some decent help!
You can use http://www.pinvoke.net/default.aspx/hhctrl.HtmlHelp to open chm help at specified topic and to have more control of how chm window shown.
How about using the Help class instead of opening the file externally

Categories