|
If you want a regex the following should work
\d{2}/\d{2}/\d{4}
Not very advanced, just checks for 2 digits followed by a slash and 2 more digits, then a slash then a group of four digits.
Sig cops got me...
|
|
|
|
|
You can use a pattern like "\d{2}/\d{2}/\d{4}" to validate only the format. You can rule out dates that clearly are invalid with a pattern like "(0[1-9]|[12]\d|3[01])/(0[1-9]|1[0-2])/(19|20)\d\d", but a pattern that would actually check if the date is valid would be extremely complex. Just imagine all the combinations to validate the correct number of days in the different months, then imagine leap years on top of that...
---
b { font-weight: normal; }
|
|
|
|
|
If the regex isn't an absolute requirement, look into DateTime.TryParse()
|
|
|
|
|
Hi all,
I want an image button (ie, fully owner drawn) where the image has some transparancy.
The button sits on a form which has a custom OnPaint which draws to the form surface, the button lies on top. So, the transparant parts of the button should show the image on the form underneath.
In the constructor of my image button class, I set the styles UserPaint, AllPaintingInWmPaint, and DoubleBuffer.
In my OnPaint override, I simply draw the button.
But it doesn't work, the background behind the button is not what I drew on the form. In fact, it seems to be the image for the standard button toolbar (in blue). No idea why.
Anyone got any pointers?
Thanks
Jon
|
|
|
|
|
The problem with Transparency and controls is that it's NOT transparent. A control cannot be made to be fully transparent. Why? Well, because when the controls parent container paints it's background, it paints around the controls it contains, leaving holes (regions) in the background where the constituent controls will show up. It's up to the controls to paint themselves into those holes. All the controls know is that they have a surface to paint on. That surface is NOT part of the parent container!
Setting a controls BackColor to Transparent tells the control to take on the background of the parent container. It does not make the control transparent! The control simulates this transparency by using the BackColor and BackgroundImage properties of it's parent container, so it blends in with the background of the parent! The control knows nothing of other child controls in any parent container, or any grandparent container.
This means that if you put, say, two 2 button controls on the form and overlap them so one button is partially obscuring the other and you make the top button transparent, you will NOT see the remaining part of the covered button through the top button! You will see the background of the parent container both buttons sit in!
Try this... Drop a Panel control on a form, then either set it's background to a bitmap image and make sure it streches to fill the entire panel, or set it's backcolor to any color. Then drop a Label control on the Panel and make it take up about 1/4th the size of the Panel. Change it's BackColor to anything, except Transparent. Then drop another Label control on the Panel and position it so that one corner covers a corner of the other Label. Change it's BackColor to Transparent and watch what happens.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi. I am using visual studio 2005 with Sql Server Express Edition. I haven't install sql server 2005 Professional edition on my machine. It works fine. The connection string is:
<add name="RealEstateConnectionString" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\RealEstate.mdf;Integrated Security=True;User Instance=True" providername="System.Data.SqlClient">
You can see I haven't hardcoded machine name and there is no absolute path.
I have open the website on another machine and it works fine. Now , i have open this project on third machine but it doesn't work and gives the following error:
"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
I think there is some problem with sql server configuration . Please help me in this regards. I will be very thankful to you.
Fahim
Great Men always help people.
|
|
|
|
|
|
Has anyone encountered a message box that pops up behind the main form? How do I fix this?
private void button13_Click_1(object sender, EventArgs e)
{
item i = new item();
Button b = new Button();
b.Text = "hello";
b.Click += new EventHandler(b_Click);
subItem s = new subItem("hello");
s.EmbeddedControl = b;
i.SubItems.Add(s);
this.myListView1.Items.Add(i); //my custom windows control
}
void b_Click(object sender, EventArgs e)
{
MessageBox.Show(this, "hello");
//this is refering to the main form in here...
}
|
|
|
|
|
Hello,
Check if your mainform was set to "TopMost = true"
All the best,
Martin
|
|
|
|
|
|
Check the properties of your mainform and make sure that topmost is set to false.
|
|
|
|
|
|
I am trying to customize a commercial component.
I found I could write something like that:
public class MyHackClass : StupidCommercialClass
{
protected override void OnAnEvent()
{
if(!someCondition)
{
base.OnAnEvent();
return;
}
....
}
}
The problem is, I still want to raise the event 'AnEvent' but I do not want to call the base class's OnAnEvent() method.
Is there a way to achieve that with reflection?
As shown in the sample I already look (without much luck) into TypeDescriptor class..
|
|
|
|
|
Does this work?
if (this.AnEvent != null)
this.AnEvent(this, new EventArgs());
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Nope, only the declaring class could fire the event.
What I need is a way to get at the underlying storing delegate.
|
|
|
|
|
TypeDescriptor is for Design-Time support of components and not for Reflection purposes.
Use typeof(StupidCommercialClass).GetField(...).GetValue(..) to get the field storing the delegate - it should be a private field having exactly the same name as the event.
|
|
|
|
|
|
How to parse generic numeric string, irrespective of whether the enter value is small int (int16) or big int (int32) or more than that. I want to parse the string as numeric (number) not as int16 or int32?
Thanks in advance
kumar
|
|
|
|
|
Hello,
I think the TryParse Method of double should do it.
You have to use "System.Globalization.NumberStyles.Number",
<br />
double d;<br />
string yourestring = ???;<br />
if(double.TryParse(yourestring,System.Globalization.NumberStyles.Number, CultureInfo.CurrentCulture, out d))<br />
{<br />
}<br />
Hope that helps you!
All the best,
Martin
|
|
|
|
|
How to Add and Remove registry key for Office 2007 (Word) Add-in dynamically during runtime (using C#). After completing installation of my Addin I wanted to remove the registry key and write (add) again when I start Office 2007 (Word) from my Program. And Word 2007 should read the registry of mine.
|
|
|
|
|
Hi Members...
I am developing a project in which i need to read the value of one default key. I wrote a code but it is showing "". Is there any way to read them? Please share your ideas with me...
thanks in advance
Pradeep
|
|
|
|
|
Hello,
following the Composite design pattern I want to create hierarchical structures of objects exploiting the following design. All possible classes inherit from an abstract base class. The base class provides an abstract method which can be used to add elements to the structure. The Add() method has to be overridden in subclasses.
Let's assume something like that:
<br />
public abstract class BaseClass<br />
{<br />
public abstract void Add(BaseClass BaseElement); <br />
}<br />
<br />
public class Element_1 : BaseClass<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}<br />
<br />
public class Element_2 : BaseClass<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}<br />
<br />
...<br />
<br />
<br />
public class Element_n : BaseClass<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}<br />
The problem is as follows: Theoretically any object derived from BaseClass can be added to any other object derived from BaseClass. Not too bad, the design is utterly flexible. But somehow I want to control which objects can be added to other objects. The idea is to perform runtime checking when objects are about to be added within the Add() method. The runtime checking shall be as uniform as possible to obtain a good design which is easy to maintain and extensible.
I have come up with the following idea. That's where the interfaces come into play.
Let's assume that objects of class Element_2 and Element_3 can be added to objects of class Element_1. I could introduce the following interface:
interface IElement_1<br />
{<br />
}
and change the accordant classes as follows:
<br />
public class Element_2 : BaseClass, IElement_1<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}<br />
<br />
public class Element_3 : BaseClass, IElement_1<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}
Now the Add() method of class Element_1 might look like that:
<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
IElement_1 element_1 = BaseElement as IElement_1; <br />
<br />
if (element_1 != null)<br />
{<br />
}<br />
}<br />
Thereby I could avoid code that checks whether BaseElement is of type Element_2 or Element_3... BaseElement has just to implement the interface IElement_1 to make sure it can be added to an object of type Element_1.
The crucial question is: May I use these pseudo interfaces for the sake of distinction in the Add() method? Is it an elegant solution or a stupid approach? Following my idea one would create a pseudo interface for each class that can accomodate other objects. The meaning of interface IElement_i would be: The class implementing interface IElement_i can be added to objects of type Element_i.
The reason why I have come up with this idea is, that in the structures I build (I'm working on a chart library) there is a manifold variety of classes (Axis, AxisLabels, AxisTitles, Legends, Series, Grid, ChartTitle...) which can be combined in various ways. To ensure a good design I'm striving for a simple runtime checking approach in the Add() methods. Otherwise the runtime checking might turn out to be annoying.
I'm grateful for any comments on my pseudo interfaces
Thanks,
Goebel
|
|
|
|
|
IMO if you want to restrict only certain objects to be added to the Add() function, then you should actually create different overloads of the function that accepts only the child classes you want.
If you have a function that accepts objects from base class then by logic it is correct for objects from inheriting child classes to be passed to the function. To use interface only to prevent this sort of things is - to me - a wrong thing to do. Is there any reason you don't want to create multiple overloads instead? (These functions can in turn call your private Add() function).
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
Edbert,
thanks for your helping reply. There is no apparent reason NOT to use overloads. I am not that experienced so didn't consider them in the first place.
A few quick questions anyway:
- Would you regard using the overloads as proper design? Say there are 5 different elements I can add to another element. I might end up with 5 overloads.
- What does happen with the former abstract Add() method? It has to be overridden in the inheriting child classes but isn't of much help. Instead the overloads bear the brunt. Just do nothing?
<br />
public class Element1 : BaseClass<br />
{<br />
public override void Add(BaseClass element)<br />
{<br />
}<br />
}<br />
- What do you mean by "These functions can in turn call your private Add() function"? Who is public, who is private?
Your reply was much appreciated!
Goebel
|
|
|
|
|
Yes, overloads are proper design. Heck, it is part of what Object Oriented Programming is about.
Since you're not going to use the Add(BaseClass element) you do not need to declare it in the base class.
You can only override functions with the same signature (i.e. takes same arguments and returns same type).
Even if you leave it in the base class you do not have to override it on child classes that do not need it.
If you do not override it in the child class the function with the particular signature will simply become unavailable for the child class.
Oh, and one more thing, what I meant by calling the private Add() is if your overloads actually do the same thing (has the same code), then you can create a private function that can be called by the overloads and receive the base class instead.
|
|
|
|