|
I have a custom component i am using in my project. It's base is entirely covered with panels and other components. When i click on it, it is the child component that is activated rather than the base component.
Is there any way to determine when a child of the base component is activated via the base component? I know it could be done with an event for each of the child components that check a variable on the base component. But i'm looking for a simpler way that fires a single event for gotfocus and leavefocus.
Note: I'm trying to make this component entirely self contained, so i'd like to implement this inside the component, rather than the parent form.
Cheers
Cata
|
|
|
|
|
The Catalyst wrote:
Is there any way to determine when a child of the base component is activated via the base component?
You mean container? "base" component is something entirely different, i.e. the base class of a derivative class.
Only one control can have focus at a time. This is universal in all window managers. Container controls can, however, receive notification messages from their child controls, although you may have a problem if you're using containers within containers.
Your container control should extend from ContainerControl , or most often one of its derivatives, UserControl . Other controls can handle the following as well, though, so long as they're parent to controls for which you want to receive messages. Again, this is rooted in Win32, so experience with Win32 programming is beneficial.
Just override the WndProc of your container. You'll get notification messages for most child control notification messages as well, so you'll need to distinguish between the handles using the Message.HWnd . You can always get a control from it's handle using the static Control.FromHandle method, too.
Keep the message handling efficient and be sure to call base.WndProc with the reference to the Message struct passed to you when done, otherwise messages won't be dispatched to their destination windows (controls) and nothing will work inside of that container.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm trying to set a control up so that it has rounded corners like a windows form. I have enabled opaqueness, and create a bitmap with alpha textures in the corner possitions. However, the components behind the current instance do not show up, instead I am left with the corners displaying the containers background.
I know that the documentation for ControlStyles says:
Note: If there is another control between the control and its parent, the current control will not show the control in the middle.
Does anyone know of a way around this? Would it be possible to blend a controls image onto the background texture when it is moved?
Cata
|
|
|
|
|
If you want to apply Visual Styles to a button like that which is applied to forms in Windows XP and newer, then P/Invoke and use the Theme API, which is documented on MSDN (lookup OpenThemeData ).
If you're looking for information about how to owner-draw atypical buttons, search CodeProject for many examples (including a pretty decent one for Aqua buttons, or those used in Mac OSX).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If you are looking to apply the Windows XP Visual Styles, you may want to take a look at Don Kackman's article[^] here on CodeProject. He used Managed C++ to create a .NET wrapper for the Theme API that Heath mentioned.
Hope that helps.
--Jesse
|
|
|
|
|
I am trying to read/write stored information in a class to a file. This particular class contains 8 DataColumn variables, which are put into a DataTable. How do I serialize and deserialize this information? It won't write or read the columns themselves, and naturally not the DataTable. I'm lost!
Another Question:
I'm still very new at C#, 5 days using it maybe. The current application I am writing will run on 4 or 5 different computers and all share the same data. Is there an easy way to do this in C#? If so, how...and just ignore the first question
Thanks for the help.
|
|
|
|
|
Search for SerializableAttribute Class in MSDN and this site or google. There is an example in MSDN.You can find more here and in google.
Mazy
"Man is different from animals in that he speculates, a high risk activity." - Edward Hoagland
|
|
|
|
|
While you can using either runtime serialization (System.Runtime.Serialization ) or XML serialization (System.Xml.Serialization ) (there is a fundamental difference, and runtime serialization is much more powerful), it's much easier to use DataSet.ReadXml and DataSet.WriteXml to read and write XML, respectively. See the documentation for those two methods for more information.
If you're sharing data between clients, then there's many things you can do. For one, you can use a database (like SQL Server, in which case use System.Data.SqlClient classes, or MS Access or another database with OLE DB drivers, in which case use System.Data.OleDb ...and ODBC and Oracle as specifically supported as well). You could also use .NET Remoting, although this is a pretty advanced topic. Make sure to pick up a book on .NET Remoting, such as "Microsoft .NET Remoting" from http://www.microsoft.com/mspress[^] or "Advanced .NET Remoting" from http://www.ingorammer.com[^]. There's also Web Services, which use HTTP as the transport, but .NET Remoting can give you two-way communication ability (if using a transport channel like the TcpChannel, not the HttpChannel which is, by nature, "one-way", or client request/server response based), meaning that you could have clients handle remote events to know when data has been updated, for example.
The database will definitely be easier and the DataSet serves well in that case, since it represents a disconnected recordset. There's a lot of designer support in VS.NET for data-driven applications, but read about ADO.NET so you understand what's happening behind the scenes.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a gif file, 256 colors, created with Paint Shop Pro.
I do
// Load the bitmap
Bitmap myBitmap = new Bitmap ("toto.gif");
// Cut it
Bitmap frame = myBitmap.Clone(Rectangle);
// Save individual frames
frame.Save("Frame1.gif", Imaging.PixelFormat.Gif);
It works OK. Latter, I want to load the saved frame
// Load the frame again
Bitmap frame = new Bitmap("frame1.gif");
This works also. But, if I try to save it again
frame.Save("Frame2.gif");
I got an external exception in InteropServices, telling me there was a problem with GDI+.dll.
Anybody had the same problem?
|
|
|
|
|
I'm not sure exactly what you're trying to do (which may help to understand the problem and help you solve it), but take a look at the Image.SaveAdd method (which Bitmap would inherit, of course) to see how to save individual frames of an animated GIF, which I'm guessing is what you're trying to accomplish.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a storyboard, a single image that contains several frames. My program cut this storyboard in individual frames, of variable size.
I now want to save these individual frames in separate files.
This part works. The gif are indeed saved.
Later I need to make copies of some of these files, after I've done some processing on memory on them.
So I start by loading the individual frames doing
Bitmap bitmap = new Bitmap("Frame1.gif");
// Then some processing
// Then I save it again
bitmap.Save("Frame1.gif", PixelFormat.gif);
And there it crashes. I have tried to do the save immediatly after the load, in case my processing was messing something, but it still doesn't work.
Conclusion: I cannot save a bitmap immediately after I load it?
|
|
|
|
|
That is weird, and I frankly don't know the answer to that. But there is a better, more efficient way of copying files anyway: File.Copy .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Search on Google groups, I had the same problem a few years back. Sorry I cant recall the resolution though
top secret
|
|
|
|
|
Hello,
I have a question on Remoting that follows:
My first server configuration file has entry:
<service>
<wellknown mode="Singleton"
type="RemotingSamples.RemoteClass1,RemoteObject"
objectUri="ServiceEndPoint" />
</service>
My second server configuration file has entry:
<service>
<wellknown mode="Singleton"
type="RemotingSamples.RemoteClass2,RemoteObject"
objectUri="ServiceEndPoint" />
</service>
Now my client configuration file has entry:
<client>
<wellknown displayName="Server1"
type="RemotingSamples.RemoteClass1,RemoteObject"
url="tcp://machine1_ipaddress:8080/ServiceEndPoint" />
<wellknown displayName="Server2"
type="RemotingSamples.RemoteClass2,RemoteObject"
url="tcp://machine2_ipaddress:8086/ServiceEndPoint" />
</client>
I want user to select the server by giving server's machine ipaddress.
Once he gives me the machine_ipaddress I want to create object
of the class the selected server implements, that is when,
machine1_ipaddress is given I have to create instance of RemotingSamples.RemoteClass1
and
when machine2_ipaddress is given I have to create instance of RemotingSamples.RemoteClass2.
How do I do this?
Please give me more details (A simple implementaion if possible.)
|
|
|
|
|
First call RemotingConfiguration.Configure passing the configuration file with your remoting sections. Then you can use RemotingConfiguration.GetRegisteredWellKnownClientTypes to get a WellKnownClientTypeEntry[] array which you can enumerate:
private object GetInstance(string host)
{
string configfile = AppDomain.Current.SetupInformation.ConfigurationFile;
RemotingConfiguration.Configure(configfile);
WellKnownClientTypeEntry[] entries =
RemotingConfiguration.GetRegisteredWellKnownClientTypes();
foreach (WellKnownClientTypeEntry entry in entries)
{
Uri url = new Uri(entry.ObjectUrl);
if (string.Compare(host, url.Host, true) == 0)
{
object[] args = {new UrlAttribute(entry.ObjectUrl)};
return Activator.CreateInstance(entry.ObjectType, args);
}
}
return null;
} Something like that should work, but look through the documentation for the classes and members used to understand exactly what's going on.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I designed a form that got 2 textboxes(i named tbUserName & tbPassword) and 2 button (btOK & btCancel).
private void btOK_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Enter Key has been pressed");
}
tbPassword_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ((Control.ModifierKeys & Keys.Enter) == Keys.Enter)
btOK_Click(sender, e);
}
but nothing happen.
Please help me as possible as you can.
Thanks.
Mr Duc Linh Nguyen
|
|
|
|
|
duclinh wrote:
if ((Control.ModifierKeys & Keys.Enter) == Keys.Enter)
The Enter key is not a modifier key, so this will never be true. Here's what you're looking for:
if(e.KeyChar == (char)Keys.Enter)
However, you don't even need to do that. Just set your form's AcceptButton to be btOK and the button will be "clicked" when Enter is pressed in your form.
Charlie
if(!curlies){ return; }
|
|
|
|
|
What is the BEST / HIGHEST PERFORMANCE method of reading data from a SqlDataReader and returning a "default" value if the value from the reader is null. I have several different methods that all work but all involve calling a seperate void to test the values or catch the null exception. I just keep thinking there has to be a better way - i.e., one "slick" and simple line of code; but I can't seem to find it???
|
|
|
|
|
if (value == null) return defaultValue; Don't rely on exceptions for this purpose because they are expensive to catch and thus decrease performance. Also, value types (like numeric types, booleans, DateTime , etc.) can't be null, so you'll already get their default value (0, false, etc.) or DBNull depending on how things are set up).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Why won't this double buffer?
I'm drawing this graph that allows you to either move value sliders or input values and redraw the graph. I've looked at tons of double buffering examples and they all seem to be doing the same or similar type of code. But my graph still flickers. BAH!
[code]public void DrawGraph()
{
this.UpdateGraphVariables();
Point[] pointarray=new Point[5];
Pen newpen = new Pen(Color.Black);
this.m_bmImageOffScreen = new Bitmap(this.Width, this.Height);
this.m_gOffScreen = Graphics.FromImage(this.m_bmImageOffScreen);
this.m_gBuffer=Graphics.FromHwnd(this.Handle);
//computational stuff
//not interesting
I do all my drawing on the bitmap...
//Set point of origin to be 50,50 on the form
this.m_gOffScreen.TranslateTransform(50,130);
this.m_gOffScreen.DrawLine(newpen,1,1,1,150);
this.m_gOffScreen.DrawLine(newpen,1,150,150,150);
//Draw X and y axis
this.m_gOffScreen.DrawLine(newpen,-3,30,3,30);
this.m_gOffScreen.DrawLine(newpen,-3,60,3,60);
this.m_gOffScreen.DrawLine(newpen,-3,90,3,90);
...
//Join the points
pointarray[0]=new Point(30,Convert.ToInt32(a));
pointarray[1]=new Point(60,Convert.ToInt32(b));
pointarray[2]=new Point(90,Convert.ToInt32(c));
pointarray[3]=new Point(120,Convert.ToInt32(d));
pointarray[4]=new Point(150,Convert.ToInt32(f));
this.m_gOffScreen.DrawLines(new Pen(Color.Yellow),pointarray);
Then I attempt to double buffer!
if (this.m_bmOldBitmap != null)
{
this.m_bmOldBitmap.Dispose();
}
this.m_bmOldBitmap = this.m_bmImageOffScreen;
this.m_gBuffer.Clear(this.BackColor);
this.m_gBuffer.DrawImage(this.m_bmOldBitmap,30,50);
}[/code]
It still flickers!
|
|
|
|
|
In InitializeComponent put SetStyle(ControlStyles.DoubleBuffer);
|
|
|
|
|
I've got that!
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
|
|
|
|
|
You also need ControlStyles.AllPaintingInWmPaint , which is documented in the ControlStyles enumeration documentation.
Also, that enum is attributed with the FlagsAttribute , which means you can save your code some time and just use:
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true); This gets compiled as a constant value so SetStyle is only called once.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Do I do one or the other or do I set the styles AND do the manual double buffering witht the bitmaps and the two graphics objects?
|
|
|
|
|
Have you enabled double buffering in your form?
Do this in your initialisation (I put it in my Form constructor after the IntializeComonent() call.
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
|
|
|
|
|