|
Agreed, link label is designed to look like a link, and changes the cursor to 'the hand'. So it should be fairly obvious to people that it is a link.
Then use Process.Start like Davey says.
Also note, that is you use Process.Start(WebAddress); and you have a browser window open already, it will navigate away from the page the user is viewing and towards the page you supplied, its like a browser hijack!
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
I have a WinForms application whose main form contains a custom user control (and that custom user control, in turn, contains other custom user controls, etc).
If I want the main form to handle keystrokes (such as Ctrl-S or Ctrl-X) without allowing the inner user controls to handle them first, is there any easy way I can guarantee that the main form will pick up the keystroke first (100% of the time)?
|
|
|
|
|
Hi,
you will need the Form.KeyPreview property, the Form.KeyDown event, and the
KeyEventArgs.Handled and KeyEventArgs.SuppressKeyPress properties.
|
|
|
|
|
Thanks a lot. The topic of the intricacies of handling keystrokes is probably worth an article in itself.
In my test application, I made a form with a listbox in it. The listbox contained several items, including an item that started with "S", and the application handled the Control-S functionality by displaying a messagebox.
Although the Control-S messagebox still showed up when Control-S was pressed while the listbox had focus, the application also highlighted the listbox item that started with "S" (default functionality for a listbox is to highlight based on keypresses regardless of which modifiers are also pressed). The only way to suppress this functionality was to set the KeyEventArgs.SuppressKeyPress property of the Listbox.KeyDown event (it couldn't be done in the Form.KeyDown event).
Thus, I can guarantee that my main form handles keypresses like I want it to, but I still have to hunt down the sub-controls one-by-one to make sure they don't handle keypresses when I don't want them to.
|
|
|
|
|
Is there a way I can limit the number of characters inside the PropertyGrid items. I want to allow only 5 characters. Please help
|
|
|
|
|
The only thing you can do is to validate the data *after* the user has already entered it. There is a third-party control, which does allow you to restrict what the user can enter. Check it out here[^].
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Is there a possiblity to attach a textbox within the PropertyGrid control griditem
so this way i can set the textbox.MaximumLength =5 or something.
|
|
|
|
|
Unfortuantely, no. The data entry portion of the PropertyGrid is not accessible and there are no hooks for "when data is being entered". So you cannot restrict what is entered while it's being entered or swap out the entry control for you own control (even if it's just a TextBox).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
|
Maybe I should have been more clear in my answer. There is no correct way to do this. The article you posted uses internal control names to find the proper control inside the PropertyGrid. The name "System.Windows.Forms.PropertyGridInternal.PropertyGridView+GridViewEdit" is internal to the PropertyGrid and could be changed by Microsoft. So this means your application may just stop working at some point.
Using Reflection (or in this case internal control names), you can gain access to any field/property/method/event in a .Net class. This includes all private and internal members. It is highly recommended that you don't do this, because again the creator of the class can change the inner workings at anytime (thus breaking your application).
That aside, the article's code is pretty straight forward. An attribute is created so that the developer can mark each appropriate property with a "format". Then the custom PropertyGrid looks for that format and restricts the input.
I *think* that you would need to:
1. Create an attribute that takes a maximum length and apply this attribute to your properties.
2. In CustomPropertyGrid, you can remove the m_TextBox_TextChanged method, because you won't need to use that to enforce the max length.
3. In CustomPropertyGrid, replace the parts of code where the m_TextBox_TextChanged method is assigned to and removed from the TextChanged event so that you set and reset the MaxLength property, respectivly.
Give it a shot, if you have problems then email me and I can help you work through it.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks Tom, I appreicated the time you took out to answer me. Can you enlightened more as you said that "the creator of the class can change the inner workings at anytime (thus breaking your application).". What about if lets say i run my application on .Net version 2.0 and even microsoft change the PropertyGrid control properties in .Net vesrsion 3.0 or so, will that effect ? Excuse me, as you have propbably have figured it out that I am a newbie and willing to explorer and learn more with people like you. Atleast, you have given me some thought to look after Reflection and what is that all about.
Thanks
|
|
|
|
|
Let's take an example. Assume that I'm a company providing a class/control that you purchased (e.g. Microsoft), and I have the following class that I provide you (the developer):
public class SomeClass {
private Int32 hiddenInt = 0;
public Int32 SomeProperty {
get {
return this.hiddenInt;
}
}
}
Now, I would compile this class and only provide you with the assembly. So in your code, you would only be able to see SomeProperty, because it's public. You cannot see hiddenInt, because it's private.
Also, let's assume you want to change hiddenInt (probably because changing it would result in some effect you desire, such as limiting the number of characters that can be entered into a text box). You can use Reflection to change this value, like so:
using System.Reflection;
SomeClass c = new SomeClass();
Type t = typeof(SomeClass);
FieldInfo fi = t.GetField("hiddenInt",
BindingFlags.NonPublic | BindingFlags.Instance);
fi.SetValue(c, 1);
So you build your application and everything works great. But now I update my class (with bug fixes or optimizations) and I change it to:
public class SomeClass {
public Int32 SomeProperty {
get {
return 0;
}
}
}
As you can see, I removed the field and simply hard-coded the 0 in the property. Since hiddenInt was not visible to consumers of my class, I am free to change or remove it. Now if you start to use my new class, then you application will be broken. Because I no longer have the hiddenInt field.
This is a simple example, where you could simply detect that the field is no longer there and ignore the "error". But in the case of the PropertyGrid, you are enforcing user input. So your users would see a change in functionality or usability, if you were to ignore the error.
Now, in the case of the article you linked to. The code uses the "internal" name of the grid's control. This name can be changed at any time by MS.
Basically, if you start using things that are not publically visible (either public or protected in C# speak), then you can run into problems.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
who did made a program that is like Pain(simple,it only draw line,rectangular...) in Windown.if you made,you can share for me.I am making it,but it is dificult
leo
|
|
|
|
|
nta_3886 wrote: help quick
help please? and even that would be a horrible subject
nta_3886 wrote: a program that is like Pain
you know, this post IS a pain
use google
|
|
|
|
|
m@u wrote: you know, this post IS a pain
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi, there are several articles about paint programs here on CodeProject. Did you care to
look at any of them?
And if you have a specific problem, ask a clear and specific question, you will get
answers as good as your questions are.
|
|
|
|
|
1.
for Sign in
-------------
Session["original"]=user_id.Text;
FormsAuthentication.RedirectFromLoginPage(user_id.Text,false);
for sign Out
------------
FormsAuthentication.SignOut();
The problem is after sign out from user acount
if I use Internet Explorer Back Option ,
I am able to enter my previous logged in page.
How can i stop it. i.e. after logout from my account, if i use Internet Explorer Back Option ,then a message will come that your session is over. How can i do this.
|
|
|
|
|
It happens because browser loads the page from the local cache.
Try this.
On Page_Load of each page.
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.ToUniversalTime());
On the Sign Out button click,
Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect(FormsAuthentication.LoginUrl);
------------------------------------------------------------
"The only true wisdom is in knowing you know nothing." --Socrates
|
|
|
|
|
|
I have a List of Tasks that I want to Search, so Have created this method on my task:
public static int CompareID(Task x, Task y) Which returns 1 if X is bigger, 0 if equal and -1 if y is bigger as it says on the MSDN site documentation. My question is how to get the List's Find method to use this alogrithmn?
My current code is
<br />
List<task> tasks = new List<task>();<br />
<br />
<br />
<br />
Task Top = tasks.Find(Task.CompareID);<br />
<br />
</task></task>
Anyone know how to get the find method to use my comparison method?
|
|
|
|
|
If you want to only have a list of possible items, then you should use a List.
Instead, if you want to have each item in a list to have some sort of reference number, a key, you should use a Dictionary.
The dictionary is located at System.Collections.Generic;
To make a Dictionary and use the basic functionality, see the following example:
<br />
public void myMethod()<br />
{<br />
Dictionary<int, string=""> dict = new Dictionary<int, string="">();<br />
dict.Add(1, "item1");<br />
dict.Add(2, "item2");<br />
<br />
dict.ContainsKey(1);
dict.ContainsKey(5);
dict.ContainsValue("item1");
dict.ContainsValue("item5");
<br />
string value = dict[1];
string value = dict[2];
}<br />
</int,></int,>
Here it will add 2 values with each an own key. "item1" with the key 1, "item2" with the key 2. So if you for instance want to find the value that belongs to the key 1 (in your example Task.CompareID), you do string value = dict.[Taks.ComprareID] .
Note here that you can use everything for the key and value, not only int and string. You are able to use objects. For objects it goes exact the same as with the int and string to find them: they have to be an exact match.
|
|
|
|
|
Your current code isn't using generics. If it was, then it would be more like
List<task> tasks = new List<task>();
</task></task>
For the compare code, look into how the List takes a custom IComparable object at creation time. I think it is just on the constructor. So you would create a class for your compare logic that implementes IComparable. Then pass that into the constructor for you list. Example:
public class TaskComparer: IComparable
{
public int Compare(Task x, Task y){}
}
...
List<task> tasks = new List<task>( TaskComparer );
</task></task>
If that doesn't work, then you need to create your own type of List that inherets from the base List<> class, override the Find and implement your own code.
|
|
|
|
|
I am working with Visual Studio 2008, .NET Framework 3.5 and C#.
I have my own Console Application that needs some functionality. Currently it is able to change the Windowtitles, read it's location on the screen, read it's width and height, send mouse-events and send key-events. This can be done to any open window, as long as I have the handle for it (which normally never is the problem).
The only thing I am missing is how to capture the messages that are send to this handle. With Spy++ I am able to see all the messages send to a window, I want the same functionality in my Console Application.
A simple example of such message will be: WM_MOUSEMOVE fwKeys:0000 xPos:10 yPos10
To make everything clear what I exactly want:
My Console Application has to read all messages send to a handle that is not created by the Console Application, for instance a window like Internet Explorer or Notepad. Those messages have to be captured.
So far I have tried both GetMessage and PeekMessage. The code I used for that is as follows
<br />
[DllImport("User32.dll", CharSet = CharSet.Auto)]<br />
private static extern bool PeekMessage(out MSG msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);<br />
<br />
[DllImport("User32.dll", CharSet = CharSet.Auto)]<br />
private static extern bool GetMessage(out MSG msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax);<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct MSG<br />
{<br />
public IntPtr hWnd;<br />
public uint Message;<br />
public uint WParam;<br />
public uint LParam;<br />
public uint Time;<br />
public System.Drawing.Point Point;<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
System.Threading.Thread.Sleep(2000);<br />
<br />
MSG msg;<br />
while (PeekMessage(out msg, new IntPtr(0x000A053A), 0, 0, 0))<br />
{<br />
System.Threading.Thread.Sleep(2000);<br />
}<br />
<br />
while (GetMessage(out msg, new IntPtr(0x000A053A), 0, 0, 0))<br />
{<br />
System.Threading.Thread.Sleep(2000);<br />
}<br />
}<br />
For me, this always results a false value for both the PeekMessage and GetMessage methods and thus no value in msg. Does anybody know how to solve my problem?
Thank you very much in advance!
|
|
|
|
|
Check this[^] out.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Sorry for the late response, but I have been working on it.
What you send is not realy what I need, that is basically built to read messages of .NET components. What I need is to read messages of any program that is running.
Through my long research I discovered Windows does not realy allow this on an easy and efficient way. You have to inject your DLL into the program in order to make it work right.
This is too much work for me...
But for me, the problem was something else, it was Visual Studio 2008.
There is a setting called "Enable the Visual Studio hosting process". This must be turned of in order to make this work. This setting can be found at:
Project >> [project name] Properties... >> Debug >> Enable Debuggers
Thank you for your information, but now I'm just working with Low Level hooks and reading from what program the message comes.
|
|
|
|
|