Click here to Skip to main content
Click here to Skip to main content

A C# IP Address Control

By , 28 Apr 2008
 

Screenshot - TestIPAddressControl.png

Introduction

Why didn't Microsoft include an IP address control in the stock toolbox for Visual Studio .NET? I needed something similar to the MFC CIPAddressCtrl class in a C# application recently, and was forced to roll my own. I tried to mimic the behavior of CIPAddressCtrl using C# here, and hopefully I've succeeded.

Background

IPAddressControl is really a composite UserControl that aggregates four specialized TextBox controls of type FieldCtrl and three specialized Controls of type DotCtrl. Here's a picture:

Screenshot - close_up.gif

The FieldCtrls do some validation and keyboard filtering, in addition to standard TextBox behavior. The DotCtrls do nothing but draw a dot.

Using the Code

Once the library containing IPAddressControl (IPAddressControlLib.dll) is built, add the control to the Toolbox in Visual Studio. From the Toolbox, just drag the control onto a form and you're ready to go. The interface to IPAddressControl is very simple.

Public Instance Properties

  • AutoHeight: gets or sets a value indicating whether the control is automatically sized vertically according to the current font and border. The default value is true.
  • Blank: gets a value indicating whether all of the fields in the control are empty.
  • BorderStyle: gets or sets the border style of the control. The default value is BorderStyle.Fixed3D.
  • ReadOnly: gets or sets a value indicating if the control is read-only.

Public Instance Methods

  • Clear: Clears the contents of the control.
  • GetAddressBytes: Returns an array of bytes representing the contents of the fields, index 0 being the leftmost field.
  • SetAddressBytes: sets the values of the fields using an array of bytes, index 0 being the leftmost field.
  • SetFieldFocus: sets the keyboard focus to the specified field in the control.
  • SetFieldRange: sets the lower and higher range of a specified field in the control.

The above properties and methods are in addition to the stock properties and methods of UserControl. Stock properties such as Text, Enabled, and Font -- as well as stock methods such as ToString() -- work as expected. The client code can register a handler for the public event, FieldChangedEvent, to be notified when any text in the fields of the control changes.

Note that Text and ToString() may not return the same value. If there are any empty fields in the control, Text will return a value that will reflect the empty fields. ToString() will fill in any empty fields with that field's RangeLower value. Also, if you are using the control to create an IPAddress, you can easily do so using this control's GetAddressBytes() method:

IPAddress ipAddress = new IPAddress( ipAddressControl.GetAddressBytes() );

History

  • 27 Apr 2008
    • Added propagation of KeyDown, KeyUp, and PreviewKeyDown events. Keys.Enter and Keys.Return will now propagate a KeyPress event.
  • 23 Oct 2007
    • ReadOnly should now really be read-only. Thanks to t_suzuki for reporting this bug.
  • 27 Sep 2007
    • Added proper event propagation for focus, keypress, and some mouse events.
    • Added AllowInternalTab and AnyBlank properties.
    • Removed superfluous code.
    • Removed a potential resource leak when calculating text size and added a null check for SetAddressBytes().
    • Compliant with FxCop 1.35.
  • 13 Jun 2007
    • Text set in design mode is persisted.
    • Removed override of AutoSize. Use AutoHeight instead.
    • [VS05] Modified size calculations to conserve horizontal space.
  • 6 Mar 2007
    • Now checks for null when parsing incoming text.
  • 21 Feb 2007
    • Added handling of [Backspace] across fields. Thanks to Antony for reporting this bug.
    • Added better handling of [Delete], and new handlers for [Home] and [End].
    • [VS05] Modified the MinimumSize property of DotControl to tighten up the spacing.
  • 5 May 2006
    • [VS05] Added Baseline to the SnapLines collection for the ControlDesigner class. Made the Text property browsable in design mode. Fixed the control sizing bug when large fonts are used.
  • 13 Oct 2005
    • Compliant with FxCop 1.32.
  • 17 Sep 2005
    • Enhanced to support Windows XP visual styles. Thanks to Carlos for requesting this.
  • 3 Aug 2005
    • Bug fix for Focused property. Thanks to Mario for reporting this.
  • 22 Mar 2005
    • Added a call to OnTextChanged() for the control when the text of any field changes. Thanks to Bertrand for pointing that out.
  • 6 Feb 2005
    • Added missing key handlers. Thanks to Norm and Ed for the heads-up on missing key handlers.
    • Added sizing.
    • Added ReadOnly property.
    • Non-standard color choices now render properly.
    • Added an event to notify clients of text change.
  • 20 Jan 2005 - Initial release.

License

This article, along with any associated source code and files, is licensed under The MIT License

About the Author

mid=5741
Canada Canada
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 4membermaryamtooty18 May '13 - 7:50 
works well.
QuestionNot working in VS2010 (.net framework 4.0)memberenzo.faffa24 Feb '12 - 6:18 
When adding the built .dll as reference, I can navigate it by object explorer but it's impossible to compile any IPAddressControlLib object and no more dll exploration is possible. It seem that after compile every reference to IPAddressControlLib is lost.
AnswerRe: Not working in VS2010 (.net framework 4.0)memberMember 993792918 Apr '13 - 9:16 
I think that i faced the same issue but i found a solution to mine if you're targeting .net framework 4.0 CLIENT PROFILE than change if to .net framework 4.0 that should be it well it did solve the issue for me
QuestionAdding [VS03] to the download link textmemberAli Fakoor19 Oct '11 - 21:31 
If possible please add the [VS03] tag to the two first items in the download section (I know they are in chronological order and the file name begins the VS03 but it is much appreciated.).
Generalthe values are working wrong in increasingmemberRapunzo13 Aug '10 - 23:40 
when I want to increase 192.168.150.25 for 1 step it being 193.168.150.25. I thing there is something wrong?
does anyone has any fix for this situation?
QuestionMAC address for an encore???membersysop@HAL9K.com17 Mar '10 - 3:37 
Anybody implemented this for MAC addresses, e.g. "aa-bb-cc-11-22-33" etc.
Generaldisplay ordinary textbox shortcut menumemberpillesoft19 Nov '09 - 2:32 
thanks for this control!
but i have one issue. i would like to copy the contents (ip address) of that control. it is not possible with right click, which is default for the textbox.
so, i would like to have the shortcut menu with Undo, Cut, Copy, Paste, Delete, Select All
 
is it possible to implement this?
Ivan
General[HOWTO] Adding this control or another to VS ToolboxmemberVincent DUVERNET (Nolmë Informatique)2 Aug '09 - 22:32 
Hi,
 
it's just a comment for people who want's to use graphical interface of VS.
 
Go to menu 'Tools'
Select 'Choose Toolbox Items'

 
Under tab '.NET Framework Components'
Click on button 'Browse'
 
Select 'IPAddressControlLib.dll' in the Release directory of the project.
 
You'll now have in the toolbox a new entry at the top called : IPAddressControlLib Components
 
++
Vincent
GeneralMDI Child Bugmembermikerileyii21 May '09 - 5:50 
I've found a problem using this control in a form set as an MDI Child.
 
public frmMDIParent()
{
InitializeComponent();
frmContainingIPControl newForm = new frmContainingIPControl();
newForm.MdiParent = this;
newForm.Show();
}
 
When the form is rendered, the IP Control is not visible. If I comment out newForm.MdiParen = this; the control is visible.
 
The workaround I did is instantiating the form in the MDI parent form's Activated event. Like this:
 
private void frmMDIParent_Activated(object sender, EventArgs e)
{
frmContainingIPControl newForm = new frmContainingIPControl();
newForm.MdiParent = this;
newForm.Show();
}
 
Anyone know why it does not show up in the first code example?
GeneralWrong layout in Korean XPmemberdisore29 Apr '09 - 0:08 
Hi!
 
Thanks for a really great control!
 
I have however noticed strange behavior on Korean Windows XP Professional. The fourth IP block is merely visible. I've uploaded a snapshot here.
 
Best regards,
Disore
 
Why is it drug addicts and computer afficionados are both called users?
--Clifford Stoll

GeneralGreat!memberjose_camacho25 Mar '09 - 21:28 
Thank you very much. I wonder why this MS-guys did not include such a control in the .NET. Maybe it has something to do with licenses and patents-rights.
 
Or maybe they just want us to do some work ... Big Grin | :-D
 

José
GeneralProblem with ShortCutsmemberStefanFrank11 Feb '09 - 6:14 
I've encountered a problem when using the IPAddressControl together with other simple controls like labels or comboboxes which have short cuts. You can reach all controls via their short cuts if other controls have the focus. If the IPAddressControl has the focus, the other controls cannot be reached via their short cuts, the focus remains in the IPAddressControl instead.
Analyzing the source code doesn't give me the deciding hint, any ideas to solve this problem?
GeneralRe: Problem with ShortCutsmembermid=574111 Feb '09 - 8:44 
Have you tried the version that is available at http://ipaddresscontrollib.googlecode.com[^]?
 
If that version doesn't work, would you please create a small project demonstrating the problem and attach it to a new issue at the Google Code site[^]?
GeneralRe: Problem with ShortCutsmemberStefanFrank23 Mar '09 - 4:17 
It seems to be a special problem in our application, which is a C++/C# mixed mode one. In a native C# application I cannot reproduce the problem. So I think we can close this issue.
GeneralThanksmemberDr.Luiji28 Jan '09 - 21:53 
Many thanks, you save me some hours of work.
have a 5.
 
Dr.Luiji
 
Trust and you'll be trusted.
 
Try iPhone UI [^] a new fresh face for your Windows Mobile, here on Code Project.

Generalgood articlememberDonsw17 Jan '09 - 17:30 
The new 2008 has a masktextbox and it still does not have an Ip mask. good work. Smile | :)
GeneralSmall request with the auto correction of too big valuemembersmudge17 Nov '08 - 3:17 
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...
GeneralThank you !membergaby_la_star12 Oct '08 - 1:40 
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 !
GeneralProblem under Vista with larger font sizesmemberStefanFrank26 Jun '08 - 0:08 
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?
GeneralRe: Problem under Vista with larger font sizesmemberMichael Chapman26 Jun '08 - 3:25 
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.


GeneralRe: Problem under Vista with larger font sizesmemberStefanFrank26 Jun '08 - 3:33 
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.
GeneralRe: Problem under Vista with larger font sizesmemberMichael Chapman26 Jun '08 - 5:08 
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

GeneralRe: Problem under Vista with larger font sizesmemberStefanFrank26 Jun '08 - 5:23 
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.
General[Message Deleted]memberMichael Chapman26 Jun '08 - 9:37 

GeneralRe: Problem under Vista with larger font sizesmemberStefanFrank26 Jun '08 - 21:30 
Perfect! Well done, you did a great job. Thank you very much for your effort.
AnswerRe: Problem under Vista with larger font sizesmembervincio7723 Mar '09 - 3:57 
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?
GeneralRe: Problem under Vista with larger font sizesmembervincio7723 Mar '09 - 21:51 
I've just downloaded the Rev44 and all works fine!!!
 
Thank you very much 4 all.
GeneralIPAddressControl -->public void Clear() need a Invokememberwangkuang522 May '08 - 16:12 
??? 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();
}
}
 
??

GeneralRe: IPAddressControl.Clear() needs an InvokeRequiredmemberMichael Chapman22 May '08 - 16:51 
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.


GeneralRe: IPAddressControl.Clear() needs an InvokeRequiredmemberwangkuang522 May '08 - 18:07 
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

GeneralRe: IPAddressControl.Clear() needs an InvokeRequiredmemberMichael Chapman22 May '08 - 19:17 
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 delegates 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:
      // This method is called from the thread that created ipAddressControl1
      //
      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.


GeneralEventsmemberamanda08926 Apr '08 - 19:14 
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.
GeneralRe: EventsmemberMichael Chapman27 Apr '08 - 4:07 
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.


AnswerRe: EventsmemberMichael Chapman27 Apr '08 - 7:42 
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.


QuestionQuestion...memberamanda08927 Apr '08 - 11:54 
Thank you. Smile | :)
 
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.
GeneralRe: Question...memberMichael Chapman27 Apr '08 - 12:11 
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.
GeneralRe: Question...memberamanda08927 Apr '08 - 12:44 
I'm converting the library because I like to understand what I am using, and I prefer single file executables.
GeneralThank you!membermory198425 Feb '08 - 23:55 
This is a great piece of code man
 
Amr Ibrahim

GeneralRe: Thank you!memberMichael Chapman26 Feb '08 - 5:35 
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.


GeneralVS 2008 Projectmembergreat_scandinavian13 Dec '07 - 20:51 
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
GeneralRe: VS 2008 ProjectmemberMichael Chapman14 Dec '07 - 5:36 
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.


GeneralRe: VS 2008 Projectmembergreat_scandinavian15 Dec '07 - 19:25 
Hi Michael,
 
Thank you for your prompt update. Just some feedback:
 
1) I think you should make a clean 2008 project, I did that with you update and it looks much better in a 2008 environment instead of referencing the 2005 project.
2) When viewing the control in the 2008 designer then the current code gives you an error saying:
"The class IPAddressControl can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again."
I made the suggested modification and I can report that it does solve the viewing problem.
 
Otherwise everything else seems works fine now under 2008,
 
LP
GeneralRe: VS 2008 ProjectmemberMichael Chapman16 Dec '07 - 9:12 
Regarding #1, what's so clean about redundant code? From a maintainence perspective, not having two copies of the exact same source code is quite clean. Another alternative would be to use soft linking in the Subversion repository, but since most people use the control from a ZIP archive, I'd rather reduce the redundancy there. It would make more sense to put the VS2008 directory as a subdirectory of VS2005, but I wanted to keep the directory convention already established in the Subversion repository.
 
Regarding #2, this control is not meant to be designed and cannot be opened in the designer when distributed as a DLL, but I agree it's bad form to not place FieldChangedEventsArgs in its own file. So I've made that change. I've also based IPAddressControl on Control rather than UserControl so that it cannot be opened with the designer from within it's own project.
 
These changes are checked into the Subversion repository[^] and ZIP archives are available from the downloads page[^].
 
Also, the VS2005 build of the control can be added as a reference to a VS2008 project with no problems. The only changes for the VS2008 project are a new GUID, a new version number, and a new resource file (in case the format changed with VS2008).
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.


NewsBug Fix: ReadOnly propertymemberMichael Chapman22 Oct '07 - 22:03 
I've submitted a new version (Revision 26) to the Code Project, but in the meantime, you can find the updates here[^].
 
If the control was ReadOnly, the [Backspace] and [Delete] keys could still change the control's contents. That bug is now fixed.
 
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.


GeneralReadOnly propertymembert_suzuki17 Oct '07 - 21:50 
Thank you very much for your good control.
 
It's Readonly, but a text in a field can be deleted.
 
The key which could be used Delete or Back Space.
 
I'm trying in order to correct the FieldControl.OnKeyDown().
 
-toru suzuki
GeneralRe: ReadOnly propertymemberMichael Chapman18 Oct '07 - 4:45 
Sorry about that. OnKeyDown() is the place to fix it. In FieldControl.cs, change line 372 to
if ( !ReadOnly && e.KeyCode == Keys.Back )
and change line 377 to
if ( !ReadOnly && e.KeyCode == Keys.Delete )

 
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.


GeneralRe: ReadOnly propertymembert_suzuki18 Oct '07 - 14:10 
Thank you very much for your prompt reply.
I'm convinced that this cord is the most excellent ip address control.
GeneralRe: ReadOnly propertymemberMichael Chapman18 Oct '07 - 16:21 
No problem. The only reason this control is any good is because of the people who found bugs or suggested enhancements. Thanks for reporting the bug.
 
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.


NewsUpdate AvailablememberMichael Chapman28 Sep '07 - 9:56 
An update has been submitted to the Code Project, but, in the meantime, the projects are available here[^].
 
I've added an AllowInternalTab property to allow the tab key to be used within the control. It is false by default. AnyBlank was added as a property to get whether any field in the control is blank. A null exception check was added to SetAddressBytes(). Superfluous code, such as an auto-generated Dispose() method, has been excised. The Graphics object returned by Graphics.FromHwnd() now has Dispose() called on it. I don't think it matters because I wrote a test calling FromHwnd() without Dispose() (but with garbage collection) many thousands of times with no resource leaks detected.
 
Also added was propagation of certain events -- GotFocus, LostFocus, KeyPress, MouseEnter, MouseMove, MouseHover, MouseLeave, Click, DoubleClick, MouseClick, and MouseDoubleClick. I thought adding mouse events would help with having tooltips work properly, but it does not.
 
And the default context menu for the contained TextBoxes has been suppressed.
GeneralSimplified Chinese XPmemberdisore24 Sep '07 - 2:00 
Hi!
 
I am using a simplified Chinese XP and is experiencing problems with the width of the control. The fourth IP field isn't visible even though AutoSize is true.
 
Do you know what the problem could be?
 
mattias

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 28 Apr 2008
Article Copyright 2005 by mid=5741
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid