|
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.
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
Thank you very much for your prompt reply.
I'm convinced that this cord is the most excellent ip address control.
|
|
|
|
|
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.
|
|
|
|
|
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 TextBox es has been suppressed.
|
|
|
|
|
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
|
|
|
|
|
Which version are you using, .Net 1.1 or .Net 2.0? The calculation of width varies, but in both cases the minimum width of the control is the sum of the calculated minimum widths of each field and dot control. It would make more sense to me if each field was too small, rather than the clipping of just one field. What happens if you try to resize the control in the form designer? Does the non-visible field always remain non-visible?
Also, AutoSize should have no effect on the control, or at least it is not being handled anywhere in the latest version of the code. The most recent versions of the code are available here[^]. The versions available from Code Project also do not use AutoSize anymore.
|
|
|
|
|
I'm using .NET 2, and probably also the version attached to this article.
It is only the last IP field that isn't fully visible, indifferent of the control width. This lead me to the function IPAddressControl.LayoutControls and the arrangement of fields and dots when the control is wider than MinimumSize.Width .
If I don't consider the calculation of offsets in LayoutControls and add a call to AdjustSize after LayoutControls in OnSizeChanged , it seems to work both in English as well as Chinese XP. Of course this means that the control can't have a custom width, and I don't think it brings any clarity to why the problem arises
I also have to mention that the problems only is seen on simplified Chinese XP (will test Japanese tomorrow), not English, nor Swedish.
By the way, thanks you for your quick response.
|
|
|
|
|
The current version attached to this article (Revision 12) has the AutoSize fix, so that should not be the problem. The newer version on Google Code has fixes for focus-related events and some enhancements, nothing related to layout.
Also, while looking at this issue, I found a potential resource leak (not Dispose() -ing a Graphics object) that I've fixed. So when this current issue is resolved I'll update the code here to include the leak fix. Thanks for forcing me to look at the code with fresh eyes.
I have an CD for Traditional Chinese XP. Do you know if that has the same problem? If so, I'll install it and debug. In the meantime, I'll see if I can find a Simplified version.
I have another project[^] that is a more generic version of this control that can be configured as an IP address control. Perhaps there is a subtle bug in this project that is not in the other project. Would you mind trying that code in Chinese XP to see if it behaves similarly? That code also has the resource leak, but I'm deferring an update until this issue is resolved in case the problem exists in both code bases.
|
|
|
|
|
I installed Simplified Chinese XP and did not witness the behavior you've described. I used the VS2005 demo project above and the only change I had to make was to move the IPAddressControl to the right a little because the Label overlapped it. It looks like crap because of the default font that Windows uses, but the layout is the same as it is with English XP.
|
|
|
|
|
Strange that you didn't experience the same problem. I downloaded the same VS2005 project above and ran it (snapshot[^]).
I also tested your other sample and took a snapshot[^]. The funny thing is that this example seems ok, but not the first. What are the main differences regarding arranging elements between the two examples?
|
|
|
|
|
I took a shot to show what I'm seeing[^]. The difference with the other project is that I used this project as a starting point and refined it somewhat. But the layout procedure is exactly the same. The method to calculate size is the same. Both projects were built on the same machine with the same IDE.
What I don't understand is why the last field would be hidden. The control gets the widths of each sub-control and uses that for its minimum width. It's like the sub-controls report one width when they're asked for size, and then use another when it's time to layout. And if the initial width was wrong for some reason, I would think that it would snap to the proper width if it was resized in the designer.
Have you tried running the IPAddressControlLib project in debug mode? LayoutControls() has an assertion that should fail if the sub-controls are wider than the control itself.
|
|
|
|
|
I have tried to run IPAddressControlLib in debug mode, and the assertion never fires, the difference is always greater or equal to zero.
I added some logging in LayoutControls() , AdjustSize() and OnSizeChanged(EventArgs e) . The thing I was interested in was the arrangement of the fields and dots, ant the fact that the fourth field visually was outside the control. But to my surprise the calculation of x in LayoutControls() were ok, the right side of the fourth field were inside the control width according to the logs.
I think this indicates that the problem isn't in your control but somewhere else in the system.
I have verified the problem on other computers running simplified Chinese, which means that the problem isn't only occurring on my computer.
|
|
|
|
|
Did you try the TestIPAddressControl EXE from the link[^] I emailed to you? It looked fine on my Simplified Chinese XP.
|
|
|
|
|
I tried it and it looked fine on my computer as well! What kind of modifications did you make?
|
|
|
|
|
It is just the latest version (Revision 20) from the Google Code repository. It has some fixes for raising GotFocus , LostFocus , and KeyPress events. Some renaming of variables and properties to make the code more in line with my newer project. Added a couple of new properties. A potential null exception has been removed. I also "fixed" the resource leak, but it's not really a leak. But I made absolutely no changes to layout and size.
I think the code you have been using is corrupt. If you grab the VS2005 project above and do a diff with your current IPAddressControl.cs, FieldControl.cs, and DotControl.cs, you should find the change that is causing your problems.
I'll post the Revision 20 source code to the Code Project, but if you need it now it's here[^].
-- modified at 16:47 Wednesday 26th September, 2007
I'm going to ensure that mouse events are raised properly. And, hopefully, get tooltips working cleanly. So it'll be a couple of days before I update the code.
|
|
|
|
|
I know that Microsoft is planning a new IP address control that supports IPV6 for release with MSVS 2008 scheduled for sometime in 2008, but I can't wait that long. I was wondering if you had IPv6 for this control?
Thanks
|
|
|
|
|
If you need it for .Net 2.0, take a look at another project of mine[^]. It's a generic control that can be customized for IPv6.
|
|
|
|