|
U can use Regular Expression Validation control.
Validation Control will not allow other characters except numbers by setting the expression as ^[0-9]+$ in validation control
|
|
|
|
|
I was thinking about instead of having a normal boring form I wanted to make a custom UI but I am blanking on how to get a UI to work. I want to make it that there are tabs, or what not and if they click on it then it will animate it as it opens.
http://www.marcmercuri.com/content/binary/InfoCenter_Old.JPG
That is just an example...
I have done alot of this in Flash but in C# I have no idea where to start. Would I have to make the tab that I want to open a sprite? An animated GIF? I searched for quite a while and found tutorials using GDI+ and graphics but almost all describe making a small animated guy move across the screen. What I want to do is have the tab that is clicked to grow across the screen and then it will show more options. If it is clicked again it shrinks back into the tab on the side.
Any ideas or links to where I might look to find something like this would be great.
Thank you,
Rob
|
|
|
|
|
Ok, I got this working. I just used a sliding graphic and it works quite well. I just made the graphic slide in when clicked then auto go back. Making it stop and go back when clicked again is easy enough to add in. I am not sure how this will behave when I stick more then one slider on top of each other but it should be fine.
This is the bar graphic I am using.. http://themcclellanfamily.com/Bar.bmp (put this in your debug folder for the project)
This is the code I am using in case anyone wants to see or tweak it. It is nothing special, it is just a scrolling graphic but my plan is to make the tabs huge, someone clicks on it, it opens, loads in the controls, buttons, etc for that topic for that tab. They click on the open tab and it will remove the controls then close itself. Adding the controls dynamically is easy, this is what was giving me issues. Anywho...here is the code
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace sliding
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Timer t;
private System.Drawing.Size playerSize;
private System.Drawing.Point playerPosition;
bool back = false;
bool goFull = false;
bool stopMove = true;
int mouseX=0;
Image pic;
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
pic = Image.FromFile("Bar.bmp");
t = new Timer();
t.Interval = 40;
t.Tick += new System.EventHandler(TimerOnTick);
t.Enabled = true;
playerSize = new Size(540, 20);
playerPosition = new Point(-300, 20);
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Form1MouseClick);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(640, 480);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.Name = "Form1";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "Form1";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1MouseClick);
this.ResumeLayout(false);
}
private void TimerOnTick(object sender, System.EventArgs e)
{
if (this.PlayerPosition.X >-20)
{back = true;
goFull= false;
}
if (this.PlayerPosition.X < -300 && back==true)
{
goFull = false;
back = false;
stopMove= true;
}
if (!stopMove && back==false)
{this.PlayerPosition = new Point(this.PlayerPosition.X
+ 15,
this.PlayerPosition.Y);
goFull = true;
}
else if (!stopMove && back==true)
{this.PlayerPosition = new Point(this.PlayerPosition.X
- 15,
this.PlayerPosition.Y);
goFull = true;
}
this.Refresh();
this.Text = " " + this.PlayerPosition.ToString() + " "+mouseX+" "+stopMove;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Graphics dc = e.Graphics;
dc.DrawImageUnscaled(pic, this.PlayerPosition);
base.OnPaint(e);
}
private Point PlayerPosition
{
get
{
return this.playerPosition;
}
set
{
this.playerPosition.X = value.X;
this.playerPosition.Y = value.Y;
}
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
void Form1MouseClick(object sender, MouseEventArgs e)
{
mouseX = e.X;
this.Text = Convert.ToString(e.X);
if (e.X < playerPosition.X + playerSize.Width && e.X > playerPosition.X && !stopMove &&goFull==false )
{
stopMove = true;
goFull = true;
}
else if (e.X < playerPosition.X + playerSize.Width && e.X > playerPosition.X && stopMove &&goFull==false)
{
goFull = true;
stopMove = false;
}
}
}
}
|
|
|
|
|
I am working on a project that needs to incorporate a C DLL. It is more like a wrapper to the DLL for C# developers. I have done some reading about unmanaged code in C#, importing a DLL and functions with the dllimport attribute. However I have not seen anything that is related to my situation.
The DLL has its own types, lets assume a connection (cxn) and a file (fh). Now I need to be able to use instances of those in C#. For example:
In C/C++ id just declare a new object
<br />
Cxn my_cxn; <br />
....<br />
Then I could go on and use that as a parameter to other functions.
How do I do this in C#?
Also, I think I am on track for strings. All of the functions in the DLL use LPCWSTR strings. So I am using the MarshalAS attribute to specify this. Example:
<br />
[DllImport("mylib.dll", CharSet=CharSet.Unicode)]<br />
static extern int CxnOpen([MarshalAs(UnmanagedType.LPWStr)] string smtp,<br />
[MarshalAs(UnmanagedType.LPWStr)] string http,<br />
[MarshalAs(UnmanagedType.LPWStr)] string dom,<br />
[MarshalAs(UnmanagedType.LPWStr)] string rep,<br />
IntPtr temp);<br />
|
|
|
|
|
Newbie quests...
How do you compile with the /unsafe option from VS2005? Also, GetHashCode returns a generated HashCode for a variable. Conversely, how do you return the original value from the code created?
Jon
|
|
|
|
|
Hi!
1. Right click on the project in the solution and open its properties. Its a checkbox on the second tab.
2. You cannot create an object from a hash code. It is not unique. Several distinct values may generate the same hash code, although code hash code algorithms have a very low chance for this to happen.
Robert
|
|
|
|
|
I am adapting TCartwright's Modal popup to use with a current project, however when I click on the Edit button, nothing happens. It just reposts with the gridview and no popup. How can I fix this? I have looked at both of our codes and don't see anything out of whack, but I am no expert at this.
This modal popup was used in TCartwright's Article.
Does anyone know why the popup would not display after clicking the edit button? I know it is probably something small that I haven't thought of.
This is the first time I have used Ajax so am at a loss in fixing it.
~Candi
|
|
|
|
|
First, if you are having problems with code from an article you should contact the author.
Second, make sure there are no popup blockers interfering with the operation.
only two letters away from being an asset
|
|
|
|
|
Thanks Mark!
I have posted this same question to the article. I was not sure if I should post it to the forums or the article. Thanks again!
~Candi
|
|
|
|
|
I have been working with a solution to this problem for a while but have not found a good solution. From a web page, you choose how many rows of text you want to display on an image. You can choose different fonts, sizes and font styles as well.
I have not found a really good solution to get the exact string width and height. Measurestring dosent work. Has anyone created a working solution for this?
Kindly regards,
Robert Johansson
|
|
|
|
|
MeasureString doesn't work? How so?
only two letters away from being an asset
|
|
|
|
|
Measurestring has problems with getting the correct size if you are using different font styles and fonts.
|
|
|
|
|
Hi,
I am quite satisfied with Graphics.MeasureString
it seems to predict well the size that will be required by Graphics.DrawString
provided you offer both methods basically the same working conditions.
I am confused about your "different font styles and fonts", both methods expect
a single font. If you want to concatenate text fragments in different fonts,
that is up to you, both for MeasureString and for DrawString.
|
|
|
|
|
There's MeasureCharacterRanges but it's a pain, buggy, and slow. I wrote a textbox control from scratch, and used the GetCharacterPlacement[^] GDI API. For your convenience:
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern int GetCharacterPlacementW(IntPtr dev, string text, int count,
int max, [In, Out] ref GCP_RESULTS results, GcpFlags flags);
[Flags]
internal enum GcpFlags
{
DBCS = 0x00000001,
ReOrder = 0x00000002,
UseKerning = 0x00000008,
GlyphShape = 0x00000010,
Ligate = 0x00000020,
Diacritic = 0x00000100,
Kashida = 0x00000400,
Error = 0x00008000,
Justify = 0x00010000,
FliGlyphs = 0x00040000,
ClassIn = 0x00080000,
MaxExtent = 0x00100000,
JustifyIn = 0x00200000,
DisplayZWG = 0x00400000,
SymSwapOff = 0x00800000,
NumericOverride = 0x01000000,
NeutralOverride = 0x02000000,
NumericsLatin = 0x04000000,
NumericsLocal = 0x08000000,
FliMask = 0x0000103B
}
[StructLayout(LayoutKind.Sequential)]
internal struct GCP_RESULTS
{
internal int lStructSize;
[MarshalAs(UnmanagedType.LPTStr)]
internal string lpOutString;
internal IntPtr lpOrder;
internal IntPtr lpDx;
internal IntPtr lpCaretPos;
internal IntPtr lpClass;
internal IntPtr lpGlyphs;
internal int nGlyphs;
internal int nMaxFit;
}
[EDIT: Oh, duh - I forgot: I used a hack that allowed me to use DrawDriverString() GDI+ function to draw the text in the resulting character positions, even though it is not made available in System.Drawing . This is sounding more like material for a whole article, not a single post... hmm. More on this when I get a chance...]
--Justin
Microsoft MVP, C# v>
|
|
|
|
|
Hello,
I hope one of you have found a solution to the following problem before. . . Thanks in advance if you have.
I'm receiving events from an external dll (an RTDServer - set up like an observer pattern), and i've a Notify method that's called when there's an update to be collected. I can then collect a System.Array with a list of updates on a separate thread.
The problem is that the list will contain a number of different update types, and i've to set different variables in an object based on the differentupdates andI've to handle that list (one by one). Which of the following are possible/advisable, and can anyone recommend a better approach?
(a) use a hashtable/sortedlist/sorteddictionary with an indexer and the names of some variables in an object. Search the list, set the object variable, and let the object call any other events needed in the get/set method.
(b) write some kind of custom enumerator for the event types or variables to be set.
(c) use a hashtable/sortedlist/sorteddictionary with an indexer an objects of type Event. Just search the list for the indexer, and call the event to subscribers.
(d) some combination of the above.
The only thing is that speed is very important, because I migt have to call these events sequentially - I haven't investigated doing a foreach on the invocation list and calling asynchronously.Although they're small, I'll have possibly a hundred of these objects, with a hundred threads collecting updates.
Any help with this problem would be much appreciated.
Thanks,
Tom.
|
|
|
|
|
Hi,
I am not sure I fully understood, why do you need an indexor ? If you are just
colledting events and passing them to one (or more) thread(s) that then must process
them, seems like you need one (or more) queue)s).
Into such queue (or any other kind of list) you could insert objects that represent
the entire update job, i.e. with all relevant information embedded.
|
|
|
|
|
Hi Luc
I have to implement an interface defined in an external program. The deal is that I have a method Notify() in my object that implements that interface, and that when there's an update, that method is called. I can then collect any updates with a method call that returns a System.Array consisting of an ID (given by me when implementing the connection), and a value. There'll be at least 20 different IDs, and the events will be unsorted in the array. I have to either update variables in the 20 objects (maybe stored in some kind of collection with the ID) or define 20 events, and store them in some sort of list for hashing.
Can I test for the speed of some of the ideas I have for the design (i don't now too much about the details of some of the objects I could use)?
I'd appreciate any help I could get on this.
Regards,
Tom.
|
|
|
|
|
Hi Tom,
it still is not clear to me why you need an indexor, or why you would have to
sort anything. Cant you just treat one event after another ? (or do you have to
process them ordered by event type ? )
if you can avoid searching, it is always better for performance. If you must search,
I would try to organize the data in such a way that the search gets optimized (e.g.
by hashing).
If the action needed for each ID is different, and IDs cover a limited range of
integers, I would consider an array of delegates and call the one that corresponds
to the ID at hand. If the ID values cover a wide range of integers, I would try
to find a mathematical mapping onto a very small range and still use an array
(basically that means look for a static hash function, rather than a universal but
dynamic one); if that fails, a HashTable seems appropriate.
Final remark: how is speed important ? are you concerned about throughput
(events per second), or latency (reaction time, from event received to event handled) ?
And do you already have an implementation and an idea about its speed, and how far
it is off what is needed ?
Greetings,
|
|
|
|
|
tobriain wrote: I have to implement an interface defined in an external program. The deal is that I have a method Notify() in my object that implements that interface, and that when there's an update, that method is called. I can then collect any updates with a method call that returns a System.Array consisting of an ID (given by me when implementing the connection), and a value. There'll be at least 20 different IDs, and the events will be unsorted in the array. I have to either update variables in the 20 objects (maybe stored in some kind of collection with the ID) or define 20 events, and store them in some sort of list for hashing.
Just so I understand... After the Notify method is called, you then call a method that returns an array of objects. Each object has an ID and a value property? Is that close?
tobriain wrote: Can I test for the speed of some of the ideas I have for the design (i don't now too much about the details of some of the objects I could use)?
You could try the Stopwatch class in System.Diagnostics . Start/Stop it at strategic points in your code. Write the elapsed time to the Debug.WriteLine method. This will show up in the debug output window pane.
|
|
|
|
|
Thanks for the swift and helpful replies.
>Just so I understand... After the Notify method is called, you then call a >method that returns an array of objects. Each object has an ID and a value >property? Is that close?
Leslie has articulated the problem better than I actually did. I'm limited by the interface i've to implement - i collect an array of IDs and values.
>If the action needed for each ID is different, and IDs cover a limited range of
>integers, I would consider an array of delegates and call the one that >corresponds to the ID at hand.
There's only four delegates, so if it's faster to search an array with the ID than a hastable to get the right object, i'll do that. Next problem: which is more efficient: firing events with the update values (referenced to delegates/then public accessor methods in the objects), or just setting the values by a call to the public accessor method of the object found in the array/hashtable myself straight away?
>Final remark: how is speed important ? are you concerned about throughput
>(events per second), or latency (reaction time, from event received to event >handled) ?
Both are important, unfortunately. . The speed concern is because of the fact that I'll have a long hierarchy of subscribers to different events fired as a result of the updates, and don't want to be sitting waiting for the method to return before going to the next row in the update array. . . It's important that the events happen in the right order, so I want (for the moment) the updates to be done sequentially. If I start doing begininvoke on the invocation list, I've no guarantee that anything will happen in order without a serious amount of synchronisation.
Hopefully it seems clearer. I'd appreciate any help on this.
Regards,
Tom.
|
|
|
|
|
I'm taking a shot in the dark here because I still may not completely understand your problem. However, that's never stopped me in the past.
I would keep a collection of objects for each ID. Actually, a list of lists would be appropriate here. Then I'd use a switch statement or a string of if/else statements to update the objects when you receive a notification:
public MyObject
{
objectList = List<List<UpdateableObject>>();
objectList.Add(new List<UpdateableObject>());
objectList[0].Add(new UpdateableObject());
objectList[0].Add(new UpdateableObject());
objectList.Add(new List<UpdateableObject>());
objectList[1].Add(new UpdateableObject());
objectList[1].Add(new UpdateableObject());
}
public void Notify()
{
Update[] updates = GetUpdates();
for(int i = 0; i < updates.Length; i++)
{
if(updates[i].ID == 0)
{
foreach(UpdateableObject obj in objectList[0])
{
obj.Value = updates[i].Value;
}
}
else if(updates[i].ID == 1)
{
foreach(UpdateableObject obj in objectList[1])
{
obj.Value = updates[i].Value;
}
}
}
}
In this case, I'm assuming the ID's are consecutive integers, but the code above doesn't depend on that. The ID's could be anything. If you have a lot of ID's you will have a long string of if/else if statements. But as long as this is isolated to a single place in your code, I wouldn't worry about it.
You can have variations on this by storing the list of updateable objects in a hashtable, as you've mentioned, by the ID. Or use an array of delegates like Luc suggested. I wouldn't create 20+ events that you trigger yourself, though. I think that would be the least efficient way to go. Just my opinion.
|
|
|
|
|
Hi,
I'm working on a screen saver that will log users out if they are outside of their allowed logon hours.
I've done this all ready in vbscript as proof of concept and I'm 95% of the way there in C#.
I'm having trouble getting the user logonHours property. It returns a System.Byte[] that should be 21 bytes. Each bit representing an hour out of the week.
No matter how I get the property it always returns as a object, and I can't access the values of the byte array to sort them out. My current code to get the object looks like this:
object objHours;
DirectoryEntry userDSE = new DirectoryEntry("LDAP://" + userDN);
objHours = userDSE.Properties["logonHours"][0];
The line that creates the object works, and I have tried creating the object 2 or 3 other ways. Through the logonHours object I cannot access the values of the array. I have also used a binary stream to convert the object in to a byte array, but the byte array returns a 48 byte array that I don't trust to stay constant in size. I would prefer to access the values through the object properly.
I need some help. It would be appreciated.
Thanks,
Dwayne.
|
|
|
|
|
i have datagrid that bound to database
when i put that row in my code error appear
datagridview1.rows.add();
i need tro allow usert to put new row just in the case of click new button
i need fast answer
thanks
md_refay
|
|
|
|
|
How or where would i look to get current cpu ussage of a spessific proccess ( in this example winword.exe)
thanks so much
crash
|
|
|
|
|
Task Manager can show you such information.
And you can get access to it programmatically by using the PerformanceCounter class.
|
|
|
|
|