|
Look, a window can't receive input if it doesn't have the focus! Period. If can't have the focus if it isn't visible! Period. If you don't believe me, read the damn Windows Manager section in the Platform SDK. The only other way is to install a hook and remove it when visible again.
And it's so much trouble to actually READ the documentation? Right. You'll learn a lot that way.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I currently have a collection of custom business objects which is a datasource for my DataGrid. I would like a property of this custom object to be an image which is displayed in the datagrid. I am using column styles and DataGridTextBoxColumns for all other properties. How do I display an image?
I need the solution to be generic, so I can't be using delegates or other solutions that require a hardcoded function for a particular image.
I have not found anywhere on the net that describes how this can be done. Does anyone have any sugguestions?
Please help.
Thanks.
|
|
|
|
|
I’m pretty sure that you'll find all that you need about DataGrid at
Windows Forms FAQ:
http://www.syncfusion.com/FAQ/Winforms/
Best Regards,
Daniel Zaharia
|
|
|
|
|
I think this is a valid solution. Any Sugguestions?
I have created a class called GridIconOnlyColumn which implements DataGridTextBoxColumn
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
{
try
{
g.FillRectangle(backBrush, bounds);
if (mobjGrid == null)
{
mobjGrid = (Prud.Controls.Grid)this.TextBox.Parent;
}
// Get Custom Object
object objRow = mobjGrid.Rows[rowNum];
//Draw Image
g.DrawImage((System.Drawing.Image)PropertyDescriptor.GetValue(objRow), bounds);
}
catch (Exception err)
{
throw err;
}
}
|
|
|
|
|
Assume my windows based program is named 'App1'.
How can I write
If App1 == Already running
{
then exit and do not run a second instance
}
thanks
|
|
|
|
|
using System.Diagnostics;
In the Main function for your app...
Process proc = Process.GetCurrentProcess();
Process[] procs = Process.GetProcessesByName(proc.ProcessName);
if (procs.Length > 1)
Application.Exit();
else
Application.Run(new Form1());
|
|
|
|
|
|
Jeff,
Shouldn't that read:
if (procs.Length > 0)
Thanks,
Alvaro
He who laughs last, thinks slowest.
|
|
|
|
|
No. The first instance of the program would never run because the Process array includes the current running process. So changing it to Length > 0 would cause the program to never run.
|
|
|
|
|
Of course!
Thanks for clarifying.
Regards,
Alvaro
He who laughs last, thinks slowest.
|
|
|
|
|
While getting the process list is one way to do it, it relies on nobody else running an executable with the same name.
The approach most people seem to use is creating a "named mutex". A mutex is an object that can only be owned by one thread. If you make this a "named" mutex, then its effect is machine wide (as opposed to just process wide).
The approach is you try to create a named mutex with a unique name (use a GUID and you'll never have to worry about some other program using the same name). If you are able to create it and own the mutex, then you're the first instance running. If you can't create it, someone else is already running.
For an example of this technique, use this link I found in a Google search:
Link
Look at the 2nd reply (third message) from "Adam".
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
|
I have a form that I need to set a vlaue in from another form. I know I can do this with a property. the problem is that form I want to set the property on is already active. The olny way I know to set the property is to do somthing like
formname f = new formname();
f.propName = my vlaue;
f.show();
this would create a new form not use the one I already have and I am at a lost as to how to set the prop in the form that is already loaded.
thanks for any help.
|
|
|
|
|
in your main form clas create a member variable (reference)
formname f;
in the load event of the main form :
f = new formname();
then in your code:
f.propName = my vlaue;<br />
f.show();
this way you always use the same formname instance..
i wish this can help..
|
|
|
|
|
dose this not create a new instance of the form and not reffrence the one I curently have open.
I was able to make it work by making it static. Is this a good way of doing it or did I gat lucky
|
|
|
|
|
I think my way (member variable) is more clear nad reasonable.
|
|
|
|
|
So, what do you want?
Do you want to set value to Properties which is already defined in Form class or your own property defined in your customized Form class?
|
|
|
|
|
I am a novice developer and am trying to do this:
I have created a custom event which I want to fire from within the constructor of MyClass. Now when it tired to fire I get a runtime error which says "Null Reference", possibly pointing at "this"-
Here is the snippet:
public delegate void MyLogEventHandler(object sender, LogEventArgs e);
public class BotNode : GoGeneralNode
{
public event MyLogEventHandler BotCreatedEvent;
public BotNode()
{
LogEventArgs myLogEventArgs = new LogEventArgs("Bot Node Created");
BotCreatedEvent(null, myLogEventArgs);
}
Question: Is it impossible to pass "this" as a parameter to an event within the constructor of a class? At this point, can I only use this within the class, or can I safely pass it as part of an event invocation.
If so:
1) Why can't I use it that way within the constructor?
2) How do I solve this?
Maybe I am just making a stupid mistake. Apologies for my ignorance.
HEELP!
Andy
|
|
|
|
|
You can't fire an event in the constructor. Here's why (and the answer to your problem). Events in .NET are based on the listener principal. Each even has a collection of listeners associated with it (by default). If there are no listeners, the event list is null. That's why you're getting the NullReference exception. You can't do this in your constructor because until your constructor finishes and an instance is created, callers must wait before attaching an event handler to the event. If you want to fire an event while your object is being created, then you should use static events which work the same way:
public class MyClass
{
public static event EventHandler Created;
public MyClass()
{
if (Created != null) Created(this, EventArgs.Empty);
}
} See how I checked if the event was null (i.e., the event handler collection is empty)? There is a more common practice for this, especially with instance events. The .NET BCL (base class library) does it throughout and it's a good idea to do in your code, that way derived classes don't have to listen to the event which is a little slower. You use a protected virtual method that raises the event and simply call that:
public class MyClass
{
public MyClass()
{
}
public event EventHandler MyEvent;
protected virtual void OnMyEvent(EventArgs e)
{
if (MyEvent != null) MyEvent(this, e);
}
}
public class MyClass2 : MyClass
{
public MyClass2()
{
}
protected override void OnMyEvent(EventArgs e)
{
if (e != null) DoSomething();
base.OnMyEvent(e);
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
1) Very good response
2) It works!
3) I learned something important.
and finally ...
4) You're my hero!
Thanks for the very good and easy to understand explanation including sample code (!). Can't ask for more than that.
Andy
|
|
|
|
|
andrewstan wrote:
3) I learned something important.
I'm glad to hear it! I may come off as a bit of an ass sometimes to some people, but this is all I'm trying to foster - education. I'm glad I could help!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
I may come off as a bit of an ass sometimes to some people
Damn the torpedoes, full steam ahead.
Andy
|
|
|
|
|
Hi.
How do i drag and move a window using the mouse, when the window do not have a titlebar???
I thought of using MouseDown, MouseMove and MouseUp to move it, but i can't seem to get it to work
As their an easier way??
|
|
|
|
|
may be this code can help you
add mousemove event and form_load event to your form and three variables x,y,click,first to your class
check this code is true or not.
private int x,y;<br />
bool click=false;<br />
bool first=false;<br />
private void Form1_MouseMove(object sender,System.Windows.Forms.MouseEventArgs e)<br />
{<br />
if(e.Button==MouseButtons.Left)<br />
{<br />
if(click&&first)<br />
this.Location=new Point(this.Location.X+e.X- x,this.Location.Y+e.Y-y);<br />
x=e.X;<br />
y=e.Y;<br />
click=true;<br />
first=!first;<br />
}<br />
else<br />
click=false;<br />
<br />
}<br />
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
x=this.Location.X;<br />
y=this.Location.Y;<br />
}
|
|
|
|
|
Great! that was exatly what i needed! thanks a bunch.
|
|
|
|