|
Hi again,
I have a textbox where the text is longer than the textbox width. When I type text in and leave, the beginning of the string shows, and focus goes on to the next box. But if I don't change the text (just tab through or whatever), the beginning of the string is cut off, leaving the end of the string visible. I do use textbox.SelectionStart = 0; , but it it only works if text is changed.
Any suggestions???
Thanks again,
Mel
|
|
|
|
|
Hm..
Maybe try to add [code]textbox.SelectionStart = 0;[/code] to the LostFocus event?
|
|
|
|
|
That's the weird part, I have the FocusLeave event.
private void txtBoxLeave(object sender, System.EventArgs e)
{
textbox.SelectionStart = 0; ...
}
Again, it works when the text is altered (even if it ends up being the exact same text), but not if nothing at all is done.
Mel
|
|
|
|
|
Maybe you can cheat a little bit?:
private void txtBoxLeave(object sender, System.EventArgs e) {
if (textbox.Text.Length > 0) {
textbox.SelectionStart = 1;
}
textbox.SelectionStart = 0;
}
Dunno if this works though...
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
It just refuses to work. I even put a messagebox in before selectionstart = 1, and the messagebox showed up ok. But no beginning of the string. (If it helps anyone get any more ideas, pressing only the left arrow before leaving the textbox is enough to get the beginning part. And I did try adding a SendKeys.Send("{Left}") to the KeyDown event, but that only sent a left to the next textbox (even though it was before the command to focus on the next textbox), which I'm not sure I understand.)
Mel
|
|
|
|
|
Ok, let me try again:
private void txtBoxLeave(object sender, System.EventArgs e) {
textbox.Text = textbox.Text + " "
textbox.Text = textbox.Text.SubString(0, textbox.Text.Length - 1)
textbox.SelectionStart = 0;
}
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
Hey,
Thanks a lot for looking again. I did try adding stuff to the text, but it was still refusing to work for me. I just posted what I found to do the trick before seeing your message.
Anyway, thanks again, and happy holidays!
Mel
|
|
|
|
|
I'm happy you got it working. You have happy holidays too!
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
Ok, got it going. It's as simple as textbox.Select(0,0);
|
|
|
|
|
how i can see the Browser Activity Monitor
ex: i open http://www.hotmail.com
and write email
and password
i need to read it by this program
-----------
Palestine
|
|
|
|
|
Hi,
How do get the screen coordinates of the mouse cursor to appear on the WinForm next to the cursor and follow the cursor around as it is dragged
across the Form?
thanks a lot.
|
|
|
|
|
You can build a really simple solution using the MouseMove eventhandler:
if(e.Button == MouseButtons.Left) {<br />
Point coordinate = PointToScreen(new Point(e.X,e.Y));<br />
<br />
}
WM.
What about weapons of mass-construction?
|
|
|
|
|
I have a project that had a Mainscreen that calls several forms via dll's. Visual inheritance if you will. There can only be one instance of each form running at a time. Therefore, I have the following class to pass each form through:
using System;
using System.Windows.Forms;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
namespace FormManager
{
public class FormLoader
{
private static HybridDictionary m_InitializedForms = new HybridDictionary();
public static void LoadFormType(Type formType)
{
Form frm = (Form)Activator.CreateInstance(formType);
if (IsAlreadyLoaded(formType))
{
frm.BringToFront();//this does not work.
return;
}
FlagAsLoaded(formType);
frm.Closed += new EventHandler(FormClosed);
frm.Show();
}
private static void FlagAsLoaded(Type formType)
{
m_InitializedForms[formType.Name] = true;
}
private static void FlagAsNotLoaded(Type formType)
{
m_InitializedForms[formType.Name] = false;
}
private static bool IsAlreadyLoaded(Type formType)
{
return ((m_InitializedForms[formType.Name] != null) &&
(bool)m_InitializedForms[formType.Name] == true);
}
private static void FormClosed(object sender, EventArgs e)
{
Form closingForm = (Form)sender;
closingForm.Closed -= new EventHandler(FormClosed);
FlagAsNotLoaded(sender.GetType());
}
}
}
So, on the mainscreen I would simply call the Form2 from a button_click event like so:
FormLoader.LoadFormType(typeof(Form2));
This works great. However, when I click on the button again, it does not bringtofront or have focus. I have done something very similar to this and it worked fine. I tried using the WIN32 API to bring it to front as well. That would instantiate another form. Still, no luck. Any suggestions would be great. Thanks in advance.
-- modified at 10:29 Wednesday 14th December, 2005
|
|
|
|
|
Instead of storign true or false as the dictionary values, you could try storing the form instances themselves. Then you could do something like
Form f = (Form)m_InitializedForms[Form2];
f.Show();
You could simply compare the value to null to decide whether to instantiate or show an existing one.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Here's your problem with the FormLoader . You check to see if the form type has been loaded and then try to BringToFront a new instance of the form. Here's a rework of your class that does what you want.
public class FormLoader
{
private static HybridDictionary m_InitializedForms = new HybridDictionary();
public static void LoadFormType(Type formType, Form parentForm)
{
lock( typeof( FormLoader ) )
{
if( eh == null )
{
eh = new EventHandler( FormClosed );
}
}
if( IsAlreadyLoaded( formType ) )
{
Form f = GetForm( formType );
f.Focus();
f.BringToFront();
return;
}
Form frm = (Form)Activator.CreateInstance(formType);
FlagAsLoaded( formType, frm );
frm.Closed += eh;
frm.Show();
}
private static void FlagAsLoaded( Type formType, Form f )
{
m_InitializedForms[formType.Name] = f;
}
private static void FlagAsNotLoaded( Type formType )
{
m_InitializedForms.Remove( formType );
}
private static bool IsAlreadyLoaded( Type formType )
{
return ( ( m_InitializedForms[ formType.Name ] as Form ) != null );
}
private static Form GetForm( Type formType )
{
return ( m_InitializedForms[ formType.Name ] as Form );
}
private static void FormClosed( object sender, EventArgs e )
{
Form closingForm = sender as Form;
if( closingForm != null )
{
closingForm.Closed -= eh;
FlagAsNotLoaded( sender.GetType() );
}
}
private static EventHandler eh;
} Hope the helps.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Curtis,
You are the man. Thanks for all of your help. I actually have to change it a bit to also control how MANY instances can be called for each form. However, I will have to take a stab at that later. When I do, do you mind if I hit you up? Thanks.
|
|
|
|
|
No problem. Thanks for the compliment. I had to do this exact same thing for an application that I build for mean people. But, the technology was new, I had never used C# before, and thought "Sure, they're a@@h0l3s, but it'll be fun." Well, it was fun while they left me alone!
If you need more help, just post more messages in this thread. I'll try to keep an eye on it. That way, everyone can share the problems and solutions.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Curtis,
Thanks for your help.
One more thing. When I close the form, I am no longer able to bring it back up.
|
|
|
|
|
Hey, sorry about that. Change the body of the FlagAsNotLoaded method to
m_InitializedForms.Remove( formType.Name ); Sorry, was removing on the Type and not the Type.Name .
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Now that I think about your solution, you may want to change all the references to formType.Name to one of two things: formType.FullName or formType . Two instances of different classes can have the same formType.Name and exist in the same project. If I include the two form classes Project1.CurtisAwesomeForm and Project2.CurtisAwesomeForm, then they will both have the same Type.Name s but different Type.FullName s and their Type s will not equate, either.
Just my two cents. <smile />
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
You have a been a huge help. Thanks a lot. It is good to see that there are still people out there willing to help without makeing such a fuss if there is a loss of understanding.
|
|
|
|
|
No problem, amigo.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Curtis,
I am trying to control the number of instances of each form as well. So, working off of the previous code, I added this:
public static void LoadFormType(Type formType, Form parentForm, int instances)
{
lock( typeof( FormLoader ) )
{
if( eh == null )
{
eh = new EventHandler( FormClosed );
}
}
if( IsAlreadyLoaded( formType ) )
{
Form f = GetForm( formType );
f.Focus();
f.BringToFront();
return;
}
Form frm = (Form)Activator.CreateInstance(formType);
FlagAsLoaded( formType, frm, instances );//
DictionaryEntry[] myArr = new DictionaryEntry[m_InitializedForms.Count];//added
m_InitializedForms.CopyTo( myArr, 0 );//added
if(myArr[m_InitializedForms[formType.FullName]].Value <= instances)//added, clearly the cast types are wrong, but you get the idea
{
frm.Closed += eh;
frm.Show();
}
}
private static void FlagAsLoaded( Type formType, Form f, int instances )//
{
m_InitializedForms[formType.FullName] = f;
m_InitializedForms.Add(f, instances);//added
}
Then I would load a form as such:
FormLoader.LoadFormType(typeof(Form2), this, 1);
"1" indicating how many instances of the form should be allowed.
Thanks again for your help.
-- modified at 8:31 Monday 19th December, 2005
|
|
|
|
|
I have just found out about the BITS protocol and think it would be perfect for the project I'm working on (an application that uploads large amounts of data to a server). The problem is that there doesn't seem to exist an BITS API for C#, just for C++. Has anyone created a wrapper for C#? If not, do you think it's difficult to do?
/Tubby
|
|
|
|
|
You could make a managed C++ wrapper around the original C++ code. This shouldn't be very hard to do, but you need to know some C++ to get it done
WM.
What about weapons of mass-construction?
|
|
|
|