m66n / ipaddresscontrollib

Automatically exported from code.google.com/p/ipaddresscontrollib
Other
62 stars 26 forks source link

Lower Field Range Bypassed by Copy-Paste #9

Closed Deantwo closed 8 years ago

Deantwo commented 8 years ago
public Form1()
{
    InitializeComponent();
    ipAddressControl1.SetFieldRange(0, 100, 200);
    ipAddressControl1.SetFieldRange(1, 100, 200);
    ipAddressControl1.SetFieldRange(2, 100, 200);
    ipAddressControl1.SetFieldRange(3, 100, 200);
}

private void ipAddressControl1_TextChanged(object sender, EventArgs e)
{
    richTextBox1.AppendText(ipAddressControl1.Text + Environment.NewLine);
}

When I paste in "222.210.210.201" it does as expected and print:

200... 200... 200.200.. 200.200.. 200.200.200. 200.200.200. 200.200.200.200 200.200.200.200

But when I paste in "10.10.10.1" it doesn't respect the field range and print:

10... 10.10.. 10.10.10. 10.10.10.1

Removing focus from a field makes the field update and change to be inside the range, but in the most cases this only means that the first field is changed unless you specifically give focus to each field. This leaves it open to get non-valid IP addresses.

Also, large negative values such as "-53.-53.-473.-26" seems to be handled really weird:

100... 100... 100.100.. 100.100.. 100.100.-473. 100.100.-473.100 100.100.-473.100

m66n commented 8 years ago

Thanks for finding this. It's a serious bug. Please let me know if the latest commit to the VS2015 project fixes this for you.

Deantwo commented 8 years ago

I was using the VS2010 project, but ok I will upgrade to the VS2015 and test it out. The version numbers seemed to be the same for both so I didn't see a reason to mention that.

By the way, have you considered NuGet support?

m66n commented 8 years ago

Unfortunately, each VS project has its own copy of the source files. I have a more abstract control -- https://github.com/m66n/flexfieldcontrollib -- that uses one set of source files across multiple versions of VS. It can be configured as an IP address control.

I found an install of VS 2010 on an older computer. I'm having some issues getting the GitHub installer from AmazonAWS right now, but once they are resolved, I'll add the changes to the VS2010 project.

Deantwo commented 8 years ago

It seems to work nicely. I do have one little complaint, it doesn't really allow for the box to programmatically be set to have blank fields. With the new change it will fill all fields with the lower range values.

I like having my box have a few empty fields to indicate that those are the ones that need changing. For example:

ipAddressControl1.SetFieldRange(0, 192, 192);
ipAddressControl1.SetFieldRange(1, 168, 168);
ipAddressControl1.SetFieldRange(3, 1, 1);
ipAddressControl1.Text = "192.168..1";
ipAddressControl2.SetFieldRange(0, 10, 10);
ipAddressControl2.SetFieldRange(1, 100, 200);
ipAddressControl2.SetFieldRange(3, 1, 1);
ipAddressControl2.Text = "10...1";

So maybe just have it ignore empty fields?

m66n commented 8 years ago

That may be due to a bug which should be addressed by the changes in VS2010 or the most recent VS2015 commit.

There is now a design time bug, where Visual Studio sets the text of the control to '0...' when it is added to a form. I've solved that in another project and just need to look it up.

Deantwo commented 8 years ago

Ah, yeah you just commited another change, guess I missed that. It works much better now. I can live with the 0... for now, but a fix for that too would be welcome.

Awesome work! I should really learn how to do usercontrols some day.

m66n commented 8 years ago

The latest commits fix the 0... bug in VS2010 and VS2015. This weekend I'll look into using the same source files across multiple versions of VS.

Regarding NuGet, I don't know what's involved in getting that to work, but I can take a look in a couple of weeks. One thing this control needs is a clean-up of the code that tries to match the theme a TextBox uses.

Deantwo commented 8 years ago

Well, iusse here is resolved so I will close this.