|
When you enter a too big value in a field, the control make an auto correction of the value to 255.
After this auto correction, the cursor is placed on the left side of the value and it's no more possible to use the key point to go to the next field.
Sorry for my English, I hope you understand what I mean.
Thank you for your work...
|
|
|
|
|
Your control is simply the best one of all the IP controls I tried, including those I've developped myself.
Even better than the native SysIPAddress32 control because I couldn't get it to behave properly in VS.
I have some suggestions :
- Property .Text of the control : replace blanks by "0" (in order to avoid we get "192..." for example). Really easy to do;
- There is some kind of little flickering when we move the parent window form. I couldn't get rid of it, I don't know where does it come from.
Thank you for your great control !
|
|
|
|
|
It seems that under Windows Vista the IPAddressControl doesn't calculate the correct width if the user changes the default font size to a larger one via the control panel.
The last part of the IP address cannot be edited and is not visible in this case.
Any ideas to solve this problem?
|
|
|
|
|
I don't have Vista, but I do not see any font change issues on XP. Do you get the same behavior using the demo project attached to this article? I just wrote a small application where I can change the font of just the Form, and then just the IPAddressControl. In both instances, the control was rendered according to the font size with no clipping of any field.
Henry David Thoreau wrote: Beware of all enterprises that require new clothes.
|
|
|
|
|
The demo attached with this article produces the same problem.
With larger font sizes I meant other DPI settings in the control panel, especially 120 DPI.
It's the same effect as mentioned in "Problem with Control and 120DPI" from May 2005.
|
|
|
|
|
OK, now I see what you're saying. It looks like it could be related to the AutoScaleMode property. The form defaults to AutoScaleMode.Font . If I use AutoScaleMode.Dpi within the control, the control (with a little modification) is sized so that all fields are visible. Are you using VS2005? If so, would you mind grabbing this dll and seeing if it's a step in the right direction? All fields are there, but the control itself is a little wider than I think it should be.
Henry David Thoreau wrote: Beware of all enterprises that require new clothes.
modified on Thursday, June 26, 2008 5:36 PM
|
|
|
|
|
Yes, all parts of the IP address are visible now. The control itself is larger as normal as you mentioned above. It ends outside the form's right edge.
|
|
|
|
|
|
Perfect! Well done, you did a great job. Thank you very much for your effort.
|
|
|
|
|
Hi,
after get the last version of control (Rev 36 for VS2005) I still have the problem.
I've try one tips that solves the problem.
In Function 'protected override void OnPaint' of the control I added at the end this line:
this.Font = new Font(SystemFonts.MessageBoxFont.Name, 8f, FontStyle.Regular, GraphicsUnit.Point);
What do you think about?
|
|
|
|
|
I've just downloaded the Rev44 and all works fine!!!
Thank you very much 4 all.
|
|
|
|
|
??? System.InvalidOperationException
Message="???????: ???????“FieldControl0”???????"
Source="System.Windows.Forms"
StackTrace:
? System.Windows.Forms.Control.get_Handle()
? System.Windows.Forms.Control.SendMessage(Int32 msg, Int32 wparam, Int32 lparam)
? System.Windows.Forms.TextBoxBase.set_Text(String value)
? System.Windows.Forms.TextBox.set_Text(String value)
? System.Windows.Forms.TextBoxBase.Clear()
? IPAddressControlLib.IPAddressControl.Clear() ?? F:\DMT_WAN\PlayerDeviceInitTool\0521\PlayerDeviceInitTool\PlayerDeviceInitTool\FormControls\IPAddressControlLib\IPAddressControl.cs:?? 243
? IPAddressControlLib.IPAddressControl.Parse(String text) ?? F:\DMT_WAN\PlayerDeviceInitTool\0521\PlayerDeviceInitTool\PlayerDeviceInitTool\FormControls\IPAddressControlLib\IPAddressControl.cs:?? 808
? IPAddressControlLib.IPAddressControl.set_Text(String value) ?? F:\DMT_WAN\PlayerDeviceInitTool\0521\PlayerDeviceInitTool\PlayerDeviceInitTool\FormControls\IPAddressControlLib\IPAddressControl.cs:?? 225
? PlayerDeviceInitTool.Data2ObjectProcessor.GetNetInfoResponseProcessor(Byte[] packets) ?? F:\DMT_WAN\PlayerDeviceInitTool\0521\PlayerDeviceInitTool\PlayerDeviceInitTool\Data2ObjectProcessor.cs:?? 339
? PlayerDeviceInitTool.DataProcessor.DataFilter(Byte[] packets) ?? F:\DMT_WAN\PlayerDeviceInitTool\0521\PlayerDeviceInitTool\PlayerDeviceInitTool\DataProcessor.cs:?? 123
? PlayerDeviceInitTool.SocketStack.UDPSocketService.UDPDataReceived(IAsyncResult ar) ?? F:\DMT_WAN\PlayerDeviceInitTool\0521\PlayerDeviceInitTool\PlayerDeviceInitTool\SocketStack\UDPSocketService.cs:?? 124
? System.Net.LazyAsyncResult.Complete(IntPtr userToken)
? System.Net.ContextAwareResult.CompleteCallback(Object state)
? System.Threading.ExecutionContext.runTryCode(Object userData)
? System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
? System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
? System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
? System.Net.ContextAwareResult.Complete(IntPtr userToken)
? System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
? System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
? System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
in my code,I've given a string from udp broadcast message that it received client IP address,
code : uictl.frmtcpip.ipAddressControlIP_address.Text = dsIPAddress;
when I written this, InvalidOperationException has happended.FieldControl.Clear() need a Invoke();
public void Clear()
{
foreach ( FieldControl fc in _fieldControls )
{
//need FieldControl Invoke
//if (fc.InvokeRequired) {
// FieldControlClear fcclear = new FieldControlClear();
// fcclear.Invoke();
//} else {
// fc.Clear();
//}
fc.Clear();
}
}
??
|
|
|
|
|
According to MSDN, InvokeRequired "gets a value indicating whether the caller must call an invoke method when making method calls to the control because the caller is on a different thread than the one the control was created on."
The best solution is to coordinate all of the calls on the control to come from the thread that created the control. Otherwise you'll need to define a delegate in your code and then call Invoke on that.
delegate void ClearCallback();
private void ThreadProcedure()
{
if ( ipAddressControl1.InvokeRequired )
{
ClearCallback c = new ClearCallback( ipAddressControl1.Clear );
Invoke( c );
}
else
{
ipAddressControl1.Clear();
}
}
Henry David Thoreau wrote: Beware of all enterprises that require new clothes.
|
|
|
|
|
I've dealed at this way,could you give me more best ideas!
IPAddressControl.cs: Exception at
private void Parse( String text )
{
Clear();//this need invoke FieldControls .Clear()
if ( null == text )
{
return;
}
int textIndex = 0;
int index = 0;
for ( index = 0; index < _dotControls.Length; ++index )
{
int findIndex = text.IndexOf( _dotControls[index].Text, textIndex, StringComparison.Ordinal );
if ( findIndex >= 0 )
{
//this need invoke _fieldControls[index].Text
_fieldControls[index].Text = text.Substring( textIndex, findIndex - textIndex );
textIndex = findIndex + _dotControls[index].Text.Length;
}
else
{
break;
}
}
_fieldControls[index].Text = text.Substring( textIndex );
}
-------------------------------------------------------------------------------------
I 've written these code to deal:
in IPAddressControl.cs:
#region Public Methods
public void Clear()
{
foreach ( FieldControl fc in _fieldControls )
{
if (fc.InvokeRequired)
{
FieldControlClear fcclear = new FieldControlClear(Clear);
fc.Invoke(fcclear);
}
else
{
fc.Clear();
}
//fc.Clear();
}
}
delegate void FieldControlClear();
**************
in FieldControl class
overide Text property
delegate void SetText(string text);
delegate string GetString();
public override string Text
{
get
{
if ((base.Parent != null) && // Make sure that the container is already built
(base.Parent.InvokeRequired)) // Is Invoke required?
{
GetString getTextDel = delegate()
{
return base.Text;
};
string text = String.Empty;
try
{
// Invoke the SetText operation from the Parent of the ToolStripStatusLabel
text = (string)base.Parent.Invoke(getTextDel, null);
}
catch
{
}
return text;
}
else
{
return base.Text;
}
}
set
{
// Get from the container if Invoke is required
if ((base.Parent != null) && // Make sure that the container is already built
(base.Parent.InvokeRequired)) // Is Invoke required?
{
SetText setTextDel = delegate(string text)
{
base.Text = text;
};
try
{
// Invoke the SetText operation from the Parent of the ToolStripStatusLabel
base.Parent.Invoke(setTextDel, new object[] { value });
}
catch
{
}
}
else
base.Text = value;
}
}
-----------------------------------------------------------
so the problem is at IPAddressControl must have safe thread to invoke FieldControl 's
void Clear() and property Text
thanks all !
xixi
|
|
|
|
|
First off, I find it next to impossible to read any code that is not wrapped with 'code block' tags. Does the code even compile? It doesn't look like it will.
And, secondly, Parse() is not a public method of IPAddressControl so you cannot be calling that directly from your code.
And, thirdly, you don't need to modify IPAddressControl at all. This control offers no guarantee of thread safety. Try using a TextBox instead of my control and you'll run into the same problem. Your code either needs to be redesigned to call IPAddressControl on the thread that created the control, or you need to define delegate s for every method that you want to call from another thread and then Invoke() them. In the case of properties (i.e., Text ) a wrapper method that calls from the control's handle creation thread must be used.
Something like this:
private void SetIPAddressControlText( string text )
{
ipAddressControl1.Text = text;
}
delegate void SetTextCallback( string text );
private void ThreadProcedure()
{
if ( ipAddressControl1.InvokeRequired )
{
SetTextCallback c = new SetTextCallback( SetIPAddressControlText );
Invoke( c, new object[] { "127.0.0.1" } );
}
else
{
ipAddressControl1.Text = "127.0.0.1";
}
}
or this (if you don't want to define a wrapper method for the property):
delegate void SetValueCallback( object component, object value );
private void ThreadProcedure()
{
string text = "127.0.0.1";
if ( ipAddressControl1.InvokeRequired )
{
PropertyDescriptor d = TypeDescriptor.GetProperties( ipAddressControl1 )[ "Text" ];
SetValueCallback c = new SetValueCallback( d.SetValue );
Invoke( c, new object[] { ipAddressControl1, text } );
return;
}
ipAddressControl1.Text = text;
}
Henry David Thoreau wrote: Beware of all enterprises that require new clothes.
|
|
|
|
|
The main control doesn't recieve key events (KeyDown, KeyUp, KeyPress, PreviewKeyDown) so there is no ability to handle Keys.Enter or Keys.Return or any other keys that you might want to handle.
I want to handle Keys.Enter and Keys.Return to simulate a button click.
|
|
|
|
|
The control does propagate a KeyPress event for allowed Keys , but not for Keys.Enter or Keys.Return . I'll look into it and get back to you in a few hours.
Cyril Connolly wrote: Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
|
|
|
|
|
I've added propagation for KeyUp , KeyDown , and PreviewKeyDown events. And KeyPress will be propagated for Keys.Enter and Keys.Return . I've submitted the code to Code Project, but it may take a couple of days to appear. In the meantime, you can grab the updated files here[^].
Cyril Connolly wrote: Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
|
|
|
|
|
Thank you.
I'm converting your project to VB, and I have a question. (I don't program in C#, and usually get confused by all the extra space caused by braces.)
What is if ( null != CedeFocusEvent ) supposed to do?
In VB it's If Nothing <> CedeFocusEvent Then and raises a compiler error:
"'Public Event CedeFocusEvent(sender As Object, e As CedeFocusEventArgs) ' is an event, and cannot be called directly. Use a 'RaiseEvent ' statement to raise an event."
If I comment the if statment in VB, it works properly.
|
|
|
|
|
CedeFocusEvent relies on an external client of the class adding a CedeFocusEvent-handler to the event. So, for safety, the class checks to make sure the event has a handler before raising the event. I don't know anything about VB.Net, but I don't think an equivalent safety check is necessary in VB.Net.
Why bother converting the library? You can just use the compiled C# DLL as a reference in a VB.Net application.
|
|
|
|
|
I'm converting the library because I like to understand what I am using, and I prefer single file executables.
|
|
|
|
|
This is a great piece of code man
Amr Ibrahim
|
|
|
|
|
Thanks. I have some ideas to make the code more efficient by reducing resource use, but I haven't had time to explore them yet.
Henry David Thoreau wrote: Beware of all enterprises that require new clothes.
|
|
|
|
|
Hi there,
It would be great if you could provide a 2008 project zip file as I am having problems placing it under VS 2008. When adding the control to a form the form designer says that there is a problem with DotControl.cs line 70:
70 this.Text = rm.GetString("FieldSeparator");
Could it be an idea to use the *.resx resource file type instead of your Strings.resources?
I used it before under 2005 where it worked great.
Thank you for your great work,
LP
|
|
|
|
|
I've added a VS2008 project file to the source code version available here[^]. The C# source code is linked from the VS2005 project.
Cyril Connolly wrote: Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
|
|
|
|