|
I understand you would like to have TextBox.Enabled=true but if you are trying to control the user's actions, you need to make it very clear to them what is expected. Upon loading or clearing the form, set the data entry controls read-only. Then upon clicking the [Add], [Edit] or whatever the button is called, the first thing you do is enable your text boxes, radiobuttons and any other controls the user is to access for data entry.
If you just hide the cursor, the user clicks on the TextBox and says "What's wrong? The cursor disappeared!" If it is disabled, it is pretty clear the only option they have is to tell the program what they want to do such as [Add], [Edit], etc.
I usually have two core methods in most of my forms: Clear() and SetReadOnly(bool value). Upon loading the form or saving a record Clear() is called which sets all the default values for the fields. One of the last lines in Clear() is the call SetReadOnly(true); to disable all the controls. The only option the user has at this point is to click [New] or [Cancel]. If they click [New], I call SetReadOnly(false); and set the focus on the first field I want them to fill in (i.e. TextBox.SetFocus();).
Just a suggestion.
|
|
|
|
|
Suppose your form has 3 controls . one edit box ,and 2 other buttons. put tabindex of one of the buttons to zero in the form load event. So that the button will get focused.
Hopes this helps.
If u can Dream... U can do it
|
|
|
|
|
If you do that way the focus is certainly on one of the buttons.
But at that moment if click the TextBox you will see the blinking cusor in the TextBox.
This is not what I want. I don't want the blicking cursor show up in the TextBox until
I click either (ADD) or (EDIT) button is clicked.
Is this clear to you?
Thanks.
|
|
|
|
|
i understood now. So try changing focus on Textbox1_mouseclick , like below
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
fousButton.Focus();
}
In my case it workd. however it is not a good solution. i am searching for some other good solution with IMessageFilter.
If u can Dream... U can do it
|
|
|
|
|
hi I tested it with IMessageFilter. Its working fine.
Try adding a MessageFilter using Application.AddMessageFilter(new TestMessageFilter());
in class TestMessageFilter handle the mouse Down message(WM_LBUTTONDOWN)
like this
public class TestMessageFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
// Blocksmessages relating to left ms button.
if (m.Msg == 0x0201)//WM_LBUTTONDOWN
{
Control c = Control.FromHandle(m.HWnd);
if(c.Name =="textBox1") // ur textbox name
return true;
}
return false;
}
}
Hopes this helps
If u can Dream... U can do it
|
|
|
|
|
I'm currently working on a simple web browser, but i can't get the simplest thing: how do i convert the text in my text box to type system.url? the web browser works and when i click a link the text box is updated, but i cannot get what's in the text box to go back to the web browser (which should be operated by a button).
Thanks in advance.
P.S. I am thinking the next thing i will try to add will be the source HTML. What property do i have to check to get this? Or what method should i use?
|
|
|
|
|
I assume you mean System.Uri, not System.Url.
Uri uri = new Uri(textBox.Text);
Alternately, you can use the TryCreate static method of the Uri class to attempt to create a URI. Unlike the above method, which throws an exception if the text of the text box is not a valid URI (for instance, if you forgot to type the "http://" part of www.google.com), TryCreate will tell you if it's a valid URI without throwing any errors:
Uri validUri;
bool isValidUri = Uri.TryCreate(textBox.Text, UriKind.Absolute, out validUri);
if(isValidUri)
{
}
p.s. You don't need to convert the text to System.Uri in order to call webBrowser.Navigate. Look at the System.Navigate method overloads[^], notice that one of them takes a string. With that, you can just call
browser.Navigate(textBox.Text);
|
|
|
|
|
Thanks. It works! and I did mean URI, thanks for telling me. So do you know how I could access the HTML of the webBrowser? Thanks.
|
|
|
|
|
pls look axWebBrowser1.Document (IHTMLDocument's type) .
If u can Dream... U can do it
|
|
|
|
|
What is the difference, and why is one better then the other?
I mean indexer vs
public foo Items(string name)
{
some code here;
return respective item;
}
Thanks,
Vandra Akos
|
|
|
|
|
on the righthand side of a statement, a function can perfectly replace an indexer.
On the lefthand side it can't.
var = object[index];
object[index] = value;
object[index]++;
Of course, one can live without indexers (as C and Java have proven) but
they make it possible to improve code readability.
-- modified at 17:07 Thursday 28th December, 2006
Luc Pattyn
|
|
|
|
|
I'm working with 2 forms Form1 and Form2. Logically Form1 is a parent form and Form2 is where a data input is requested from user. When Form2 opened upon Form1, user enters some data and Form2 exits. When Form2 exits, the datagrid in Form1 must be updated with new value.
I'm trying to update datagrid with a code inside Form2.cs :
//inside Form2.cs, a method of click of a button
...sql operations bla bla
Form1 f = (Form1)this.owner;
f.fillDataGrid(); // this method belongs to Form1
this.Close();
But..... Datagrid doesn't always update, sometimes works. Any idea?
A non-smart way I tried, to use focus event; but it doesn't focus anyway. Plz help
may the force be with you, always
|
|
|
|
|
Hi,
in this scenario, define your entity object as a class, let Form1 have an static object of that class, in form two set the value for the static instance, then when u go back to form1 , do the data binding..
like this..
Form1
{
public static CEntity objEntity;
someclick()
{
Form2.showDialog()
Datagrid.databind(objEntity)
}
}
CEntity
{
Public string column1;
Public string column2;
}
Form2
{
someevent()
{
Form1.objEntity.column1 = textbox1.Text;
Form1.objEntity.column2 = textbox2.Text;
}
}
Cheers
|
|
|
|
|
Form1 f = (Form1)this.owner;
f.fillDataGrid(); // this method belongs to Form1
this.Close();
if these code wrote in the form2's closing or closed event?
I want to make some friends here
|
|
|
|
|
yes, it's written in closed event in a different solution..
|
|
|
|
|
I have an that on startup I want the main form to be hidden and activated from System Tray on Click. It works but the main form is always visible on startup????
Any help appreciated
Mike
|
|
|
|
|
Can be accessed to visible property from properties window in design view
|
|
|
|
|
Form properties does not contain a visible property but I tried all the basic stuff Hide(), visible = false in the _Load event but for some reason doesn't work. Even tried creating ApplicationContext.MainForm.visible = false in Main()???
private void Form1_Load(object sender, System.EventArgs e)
{
Rectangle rct = Screen.PrimaryScreen.WorkingArea;
Point pt = new Point(rct.Width - this.Width, 0);
this.Location = pt;
notifyIcon1.Visible = true;
this.Hide();
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
notifyIcon1.Visible = false;
}
private static bool isVisible = false;
private void notifyIcon1_Click(object sender, System.EventArgs e)
{
if (isVisible)
{
this.Visible = false;
isVisible = false;
}
else
{
this.Visible = true;
isVisible = true;
}
}
Thanks
|
|
|
|
|
Any code remain in designer.cs; for example a visible property with true value?
|
|
|
|
|
NO here is the InitializeComponent properties for Form1
//
// Form1
//
this.AutoScale = false;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(162, 511);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Contact Manager";
this.TopMost = true;
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
???
Mike
|
|
|
|
|
In your form's constructor write this line
this.Visible = false;
Regards
|
|
|
|
|
|
Fine. Put the same line of code in the Form.Shown event handler. You have to handle the event first of course, and it's present only in DotNet 2.0. If you use older versions you can use the Paint method instead and make a flag whether you want to hide or not.
Regards
|
|
|
|
|
That worked but the form came up then went invisible?
Any insight into how I can keep it from coming up in 1st place?
Thanks all for your help
Mike
|
|
|
|
|
Alright. I got a much better idea. Simply in the designer or in the constructor set the Form's Opacity to 0 (Zero). This way it will never show up.
Regards
|
|
|
|