|
Does anyone know how to convert a .NET bitmap to a DIB? I have tried to port code from C++ without success, so I would appreciate any help. Thanks alot
|
|
|
|
|
isn't a DIB just the method bitmaps use to store? and do you want to convert in realtime or just with an application? if it's the latter you might want to use something like PainShopPro or AdobePhotoShop etc. but if it's in realtime i'm not sure. wouldn't you use the System.Drawing.Imaging controls?
surgeproof.
-----------------------------------------------
looking for hosting?ithium is good.
|
|
|
|
|
Hi all!
I'm a bit new to C#. I am developing a Windows application. I've spent a few weeks designing this application. I want the windowsapplication to be the client in my server/client system. I want to connect the server to a database and bring back the data from the dB to the client. As I said, I'm new to C#, and not a very experienced programmer. Where and how do I start implementing this system?
Grateful for all the help I can get!
/Martin
|
|
|
|
|
The first thing to do is to read through the topics in the .NET Framework SDK[^] (also installed on your machine as part of the .NET Framework SDK and VS.NET). Specifically, take a look at Accessing Data with ADO.NET[^]. CodeProject also contains a wealth of information, but familiarize yourself with the basics of .NET development first (i.e., what an assembly is, what managed code is, how C# relations to the .NET Framework and managed code, etc.).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a class with a property which I want to bind to the selected value of a Listbox.
I use the databindings property of the listbox, and the binding work fine...when you select a different value from the listbox, it updates the objects property. The problem is that when you lose focus on the listbox, the selected Index gets reset to -1...Any thoughts??
Gregg R
|
|
|
|
|
Are you using ListBox or ListView?
For ListView the default property for HideSelection is true, so when it looses focus, it seems like the selection is gone. If you set that to false, the listview will show selection after focus is lost.
If it's ListBox, it shouldn't set the selected index to -1, unless you're doing it programmatically somewhere in your code.
|
|
|
|
|
I am using Listbox. No, I am not setting the index back to -1...Im just so confused...
I change the binding to a text box and it works just fine...
Regards
G
|
|
|
|
|
OK...Heres the situation:
I set the ValueProperty of the listbox to a int property, whereas the property on the object was string...when the listbox updated the object, it casted int to string, but when the object tried to set the ValueProperty it couldn't due to the type conversion.
Probelm solved.
Thanks anyway
GR
|
|
|
|
|
There's nothing exposed in the class nor available through reflection. RegQueryValueEx is used internally to get the value.
So, you'll have to P/Invoke RegQueryValueEx and get the type for yourself. If you need it; otherwise, try calling GetType from the return value of RegistryKey.Getvalue and make assertions based on that. If you get back System.String , you know it was either REG_SZ , REG_MULTI_SZ , or REG_EXPAND_SZ (in the latter case, search for occurances of '%' to determine exactly, and call Environment.ExpandEnvironmentVariables if you want to expand the string). If you get System.Int32 , you know it was a REG_DWORD . For System.Int64 , assume REG_QWORD . If you bet a System.Array , you can either double-check or assume a byte[] array and know that the registry type was REG_BINARY .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the answer... but
when I do GetType() I have the type of the object while I debug it (I can see which type it is). But how can I check the type programmatically?
of course these following lines are wrongly written, but how can I do correctly these tests in order to correctly cast the object given by RegistryKey.GetValue()?
[CODE]
if (ob.GetType() == System.String)
{ // proceed string }
else if (ob.GetType() == ...)
{ // proceed other objects }
[/CODE]
How can I write such a test?
Thanks.
|
|
|
|
|
Similar to how you did it. Familiarity with such type-checking code is often necessary:
object value = reg.GetValue("SomeName");
if (value is string)
{
}
else if (value.GetType() == typeof(int))
{
}
else if (value.GetType() == typeof(long))
{
}
else if (value is Array)
{
}
else throw new InvalidOperationException("Unknown registry key type."); I used two different ways to determine type. There's the is keyword which actually translates to the simple, one-line IL instruction isinst , but you can only use a reference type (which Int32 and Int64 aren't) as the second operand. You can also use obj.GetType() == typeof(type) , specifying the type at design-time. typeof is a keyword that gets the type and hardcodes it in the generates instructions. If you want to compare two unknown types at runtime, use objA.GetType() == objB.GetType() or the same with the Equals (instead of == ) method (the override for Type.Equals compares types, which includes the assembly name information - not just the namespace and class/struct/interface/enum name).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
aaah... ok I see... That's it. That's what I was searching for.
Thanks a lot!
so, for testing an System.Array object, I have to use the "is" keyword or the typeof() function? I saw that REG_MULTI_SZ are considered as System.Array in .NET... I guess this is an array of "String"...
|
|
|
|
|
You're right - I wasn't thinking. A REG_MULTI_SZ would be an array. In that case, first do a simple check for the System.Array type, then you could get the first element and check it's type. It'll either be a String or Byte so use typeof since Byte is a value type.
Using is is slightly faster (1 or 2 instructions as opposed to 2 or 4 - you make the call how important that is) than using typeof , but can only be used when the second operand is a reference type. Below is an IL comparison of using each(str is a variable referencing a String ):
ldloc.0
isinst [mscorlib]System.String
ldloc.0
callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
ldtoken [mscorlib]System.String
call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(
valuetype [mscorlib]System.RuntimeHandle)
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You know this inverted shortcut icon on top of each page in VS.NET help; you're supposed to click on it, and it drops down a yellow menu that makes you filter the page by C#, VB or JScript. Well, I have to do this for each page. I want it to stick. Can I do that?
Thanks.
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
It is supposed to persist for the class reference, but often does not persist for technical articles where such a feature is enabled. This just has to do with the information stored in the MSHelp metadata in each page and any cookies that are created (or aren't created, which is the problem with not being persisted).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
i want to redirect a certain window output into my application???????
thanx
|
|
|
|
|
First off, is this a WinForm or WebForm environment? If it's web, are you using frames within the same "window"? Or, are you wanting 2+ separate windows to talk to each other?
This is a start. Let me know.
Michael Flanakin
Web Log
|
|
|
|
|
He wants to redirect the output of another app that he didn't write, like Word or Excel, to a window in his app. Something like PCAnywhere or Remote Desktop Connection.
RageInTheMachine9532
|
|
|
|
|
yes i want to redirect window like excel or word into my app like PcAnyWhere
|
|
|
|
|
Well, at least your question wasn't as simple as I was thinking. Then again, maybe that would've been better. Unfortunately, I don't have a good answer for you. I could make a few speculations, but without playing around with it, your guess is as good as mine. Sorry.
Michael Flanakin
Web Log
|
|
|
|
|
This has been bugging me for awhile now. Can someone give me an example where you would use Application.Run without parameters?
|
|
|
|
|
All Application.Run does is start the message pump. If you give it a window, it will dispatch messages to the window and will automatically terminate the pump (post messages like WM_QUIT ) when that window is closed. You can use Application.Run() to simply start a message pump without displaying a form. You can later call Application.Exit to terminate the pump (also known as the application message loop).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your response Heath. I'm still a little confused though. I'm pretty familiar (although not an expert) with the message pump and the role Application.Run plays in creating it. I guess what I'm confused about is if I call Application.Run without specifying a form then how do I go about getting the window handle for use in the SendMessage or PostMessage api's? In other words, how can I actually use the message pump that Application.Run creates? Does the NativeWindow class somehow factor into all of this?
|
|
|
|
|
Consider the following example:
using System;
using System.Drawing;
using System.Windows.Forms;
public class Test : Form
{
static void Main()
{
Test t = new Test();
t.ShowDialog();
Application.Run();
}
TextBox tb;
public Test()
{
tb = new TextBox();
tb.Location = new Point(8, 8);
Controls.Add(tb);
Button b = new Button();
b.Location = new Point(tb.Right + 8, tb.Top);
b.Text = "Click";
b.Click += new EventHandler(b_Click);
Controls.Add(b);
}
private void b_Click(object sender, EventArgs e)
{
MessageBox.Show(tb.Text);
Application.Exit();
}
} Now, I'm not sure why you'd want to do this, but you could. It's most likely that this would be handy when you want to have a dialog that doesn't act as the main window handle for an application that receives general application messages posted to the pump. You'll notice (if you compile and run this) that closing the dialog doesn't quit the application. Perhaps someone might have a good reason for using such an approach.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Interesting. I never would have thought that the button click message would have been dispatched correctly in this code. Thanks for the example. The reason I was asking is because I have to be able to use DDE in a service or console application so I was experimenting with different ways of creating the message pump without displaying a form. I have successfully used Application.Run with the form parameter, but it seems like a hack since the form is always hidden. I wonder if I could do something similar with the NativeWindow class? (Just thinking out loud!)
By the way, DDE sucks.
|
|
|
|