|
I have my own custom user control, let's call it UCHost. This control hosts another one of my user controls (hot button).
What I would like to do is to have UCHost drawn and after it is finished I would add some drawing logic, do some neat transparency tricks on top of it, etc...
The problem is that when I capture OnPaint in UCHost, regardless of the fact that I have its styles set to UserPaint, AllDrawingInWMPaint, etc. - the button always redraws himself.
I tried to override paint in UCHost like this:
...
base.OnPaint(e);
MyPostProcessingOfUCHost(e);
...
But the hot button control always paints over my post processing.
Then I removed base.OnPaint() and was astonished to find out that the button is STILL drawn. I hooked to OnPaintBackground, removed base call but the button is STILL drawn.
How to solve this problem? How to have user control that has children user controls first draw all children, and then draw some cool and fancy stuff on top of them?
Tomaz
|
|
|
|
|
Does anyone know if it is possable to read all the required elements of an Emun from an xml file for example at runtime? I was think when the class gets constructed?
|
|
|
|
|
The short answer - Yes
The long answer involves creating a temporary assembly and creating the definition of the enum in C# code in a string then using the C# compiler services ( a set of C# classes used to compile .NET code. Very simple to use. ) to compile the C# code into a new assembly (in memory, on disk, in a database or wherever). Once compiled and loaded you should be able to use the type like any other .NET Enum
This can be done on the fly with any code, the dynamic assemblys can reside in memory and they do not need to be persisted to disk (however .NET might write out some temporary files, but these should get deleted)
Cheers, James
James Simpson
Web Developer
imebgo@hotmail.com
|
|
|
|
|
ya I read about that somewhere, I guess that is the only way then. It look fairly complex but will give it a try.
I am guessing that I will have to read the values from an xml file build the assembly, compile it, then expose the enum to the user somehow....
Anyways Thanks For Your Help.....
|
|
|
|
|
I am trying to grasp how to use select, update, insert and delete command.
I tried reading from some books Programming C# by Oreilly but it just doesnt really explain it in detail.
I was hoping if anyone can point me to some article (don't seem to have them at code project) where i can learn how to perform the above operations on MS ACCESS databases.
thanks
|
|
|
|
|
Look at OleDbConnection or OdbcConnection (Framework 1.1, some people have indicated that ODBC seems to perform better than OLE DB when invoked from C#).
Simple example:
using ( OleDbConnection conn = new OleDbConnection() )
{
conn.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"User ID=Admin;" +
@"Data Source=FPNWIND.MDB;" +
@"Mode=Read|Share Deny Read|Share Deny Write";
using ( OleDbCommand cmd = new OleDbCommand() )
{
cmd.CommandText =
"SELECT CategoryName FROM Categories ORDER BY CategoryID";
cmd.Connection = conn;
conn.Open();
OleDbDataReader rdr = cmd.ExecuteReader();
try
{
while ( rdr.Read() )
{
System.Console.WriteLine(
"Category: {0}",
rdr.GetString( 0 ) );
}
}
finally
{
rdr.Close();
}
}
} To try this, create a new C# console application, paste into Main and add using System.Data; using System.Data.OleDb; at the top.
This code opens the FPNWIND.MDB database (supplied with Office 2000) and outputs a list of all known categories to the console.
For simple manipulations of data, use OleDbCommand 's ExecuteXxx functions. If you don't expect any results (for example, if you're running an INSERT , UPDATE or DELETE statement), use ExecuteNonQuery . If you only want a single data value (the first column of the first row of the results), use ExecuteScalar .
If you have an OleDbDataReader open on a connection, you can only scroll forwards through the data, and you cannot modify the data. You cannot do anything else with that connection until you have either read all the data (Read returns false ) or have closed the reader.
ADO.NET does not have an equivalent of classic ADO's live update of recordsets. The closest is essentially a batch mode involving a DataSet (an offline cache of one or more DataTable s) and an OleDbDataAdapter . DataSet and DataTable are general classes; you use a DataAdapter from the appropriate provider to fill the data set or table and reflect any modifications back to the data source.
|
|
|
|
|
Is it possible to hook(MouseHook) another process/application using C# ?
VikramS
|
|
|
|
|
|
Hi,
i used ControlPaint.DrawCheckbox() method, but the checkbox is not drawn with XP Theme (FlatStyle.System). Is it possible to use ControlPaint class with XP Styles?
.:[Greetz from Jerry Maguire]:.
|
|
|
|
|
It doesn't seem like it. You might want to use this[^] instead.
|
|
|
|
|
Try calling Application.EnableVisualStyles(); in Main before anything else. This mostly worked for me (I'm still having problems with my toolbars not looking right.)
When all else fails, there's always delusion.
- Conan O'Brien
|
|
|
|
|
Yep, you're right, my code is
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new MyForm());
otherwise the styles are not set right, i guess it's a framework error that i have to call DoEvents().
I have found a solution do draw controls theme aware via xp theme api, thanks.
.:[Greetz from Jerry Maguire]:.
|
|
|
|
|
Hi, how do you minimize your app to system tray in C#/.NET?
norm
|
|
|
|
|
Add a NotifyIcon to your form and assign it an icon.
set visible = false if you do not want it to be there all the time.
In the event handler where you want the app to minimize to the tray do something like:
private void btn_MinimiseToTray_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true;
}
and reverse it all when the icon is clicked or on a context menu etc....
|
|
|
|
|
Thanks! I successfully send the app to system tray. But I am having some trouble trying to restore it from the tray.
private void NotifyIcon_Clicked(object sender, System.EventArgs e)
{ //None of this help, the form just disappeared, never to come back.
WindowState=FormWindowState.Normal;
ShowInTaskbar=true;
BringToFront();
Focus();
Visible=true;
return;
}
I just need one more tip for this.
norm
|
|
|
|
|
did you try Activate() ?
Free your mind...
|
|
|
|
|
Thanks. But, yes I did. Activate didn't work
norm
|
|
|
|
|
Hi Guillermo, I've got it working - well, the title bar didn't get repainted properly. Part/Chunk of it (Titlebar) appears dark. I called Invalidate(), which got rid of the problem in client area, not the title bar...
private void NotifyIcon_Clicked(object sender, System.EventArgs e)
{
WindowState=FormWindowState.Normal;
ShowInTaskbar=true;
BringToFront();
Focus();
Visible=true;
ClientSize = new System.Drawing.Size(292, 318);
Location = formLocation;
Invalidate();
return;
}
private void Form_Clicked(object sender, System.EventArgs e)
{
formLocation = this.Location;
WindowState = FormWindowState.Minimized;
ShowInTaskbar = false;
notifyIcon.Visible = true;
return;
}
norm
|
|
|
|
|
Good.
When I did it, I used Form.Hide() instead of changing the windowstate, so I didn't have the problem of repainting. When I clicked on the taskbar icon, I used Form.Show(). In that way, it did good for me..
Free your mind...
|
|
|
|
|
Thanks, it's working just fine now. I hide the form, as supposed to minimizing it.
norm
|
|
|
|
|
What i am doing is to generate a TrayIcon and use this code:
// Public Bool for Closing the app
bool boolAlowClose = false;
// Press the closing Button at the app
protected void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!boolAlowClose)
{
this.m_notifyicon.Visible = true;
this.Hide();
e.Cancel = true;
}
else { e.Cancel = false; }
}
// ContextMenu from Trayicon to view the app again
private void cmnu_View_Form_Click(object sender, System.EventArgs e)
{
this.m_notifyicon.Visible = false;
this.Show();
}
// This is the Menu "Close" hat close the application
private void cmnu_Menu_Close_Click(object sender, System.EventArgs e)
{
boolAlowClose = true;
this.Close();
}
Hope this will help!
Matthias
|
|
|
|
|
|
im writing a new control, and i need to pass information to the click event, how do i add data to then EventArgs so that when i create a new project and place this control in the form , the click even of that control will give me more data inside the EventArgs?
(i know i can create a class the inherits from EventArgs and add the info in there but what do i need to do, so that it will send that new class to the on_click event)
void on_click(object sender, System.EventArgs e)
|
|
|
|
|
Hi,
why you need to serve the data via the event? It's also possible to say:
void OnClick(object sender, EventArgs e)
{
((MyControlType)sender).MyDataProperty ...
}
you could read and write everything you need there.
.:[Greetz from Jerry Maguire]:.
|
|
|
|
|
You need to:
1) inherit from the System.EventArgs class with a new class eg:
public class MyControlEventArgs<br />
{<br />
private string AnExampleDataMember<br />
}
Then create a delegate for that type of event
public delegate void MyControlEventHandler(object sender, MyControlEventArgs e)
And then create the event using the newly created delegate.
Create data memebers in MyControlEventArgs for all the data you need to pass into the event. Pass an instance of the new args class into the new handler.
Cheers, James
James Simpson
Web Developer
imebgo@hotmail.com
|
|
|
|