|
I think you are trying to handle the Key event at form level. By default the KeyPreview of the Form is false. Make it True and check whether the events are handled or not.
|
|
|
|
|
Hi All,
I have a class called Variable
[Serializable]
class Variable
{
public string varName;
public string dataType;
public string scope;
public string comment;
......
}
then i have a class VariableCollection
[Serializable]
public class VariableCollection
{
private ArrayList varCollection;
//private Variable[] varCollection;
public VariableCollection()
{
//
// TODO: Add constructor logic here
//
varCollection = new ArrayList();
//varCollection = new LogicalBlock.Variable[100];
}
public ArrayList VarCollection
{
get
{
return varCollection;
}
set
{
varCollection = value;
}
}
}
Now i want to serialize VariableCollection ,i will initialize ArrayList having Variable objects and give it to VariableCollection and then
use following code to serialize VariableCollection
LogicalBlock.VariableCollection varcollect = new LogicalBlock.VariableCollection();
varcollect = var;//var is of type Variable
varcollect = var1;//var1 is of type Variable
varcollect = var2;//var2 is of type Variable
XmlSerializer serial = new XmlSerializer(varcollect.GetType(),"LogicalBlock");
Stream stream1 = new FileStream("MyFile.xml",
FileMode.Create,
FileAccess.Write, FileShare.None);
serial.Serialize(stream1,varcollect);
stream1.Close();
but it gives exception "System.InvalidOperationException"
in VariableCollection if i use Array instead of ArrayList it works fine but i dont want to use Array.
How should i Serialize(XML) collection having ArrayList and not Array??
Any Ideas??
Thanks in Advance.
TusharM.
|
|
|
|
|
thats it?????
i'm glad for you......
|
|
|
|
|
Yeah i got it i should Derive VariableCollection from CollectionBase and strongly Type the collection to be of Type Variable...
Thanks
TusharM
|
|
|
|
|
The ArrayList is Serializable , you should check out the XmlArrayAttribute[^] class, this can be used to tell your XmlSerializer to serialize a particular class member as an array of XML elements.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Please how in C# to programmatically import and export data tables between the desktop and a remote device? Using ActiveSync, or another?
Thanx
|
|
|
|
|
I've written a .NET Windows Forms application with a Form that uses a special font. If I need to use this particular font on all machines, what is the best way of going about this? Do I have to install the font into Windows\Fonts? Could I just embed the font in the app resources? What is the most pain free way?
Judah Himango
|
|
|
|
|
Judah Himango wrote:
Do I have to install the font into Windows\Fonts?
Yes. You can make the Font file part of your MSI installation package. Easiest!
Judah Himango wrote:
Could I just embed the font in the app resources?
Yes, but then you would have to unpack the Font file and install it in the Fonts folder. PITA!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Erg well I was hoping there'd be an easier way, like using a font that simply sits alongside the .exe, no font registration required but I suppose making an installer won't be too much trouble.
Judah Himango
|
|
|
|
|
i want read a GIF file to stream and then write stream to another place,but i find that my GIF file is diffirent from the old one, it is ugly then the old one, why
this is the code
System.Drawing.Bitmap TargetBitmap = new System.Drawing.Bitmap(bmp,bmp.Width,bmp.Height);
System.Drawing.Graphics bmpGraphics;
bmpGraphics = System.Drawing.Graphics.FromImage(TargetBitmap);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width,bmp.Height);
bmpGraphics.DrawImage(bmp,rect,rect,System.Drawing.GraphicsUnit.Pixel);
TargetBitmap.Save(mstream,System.Drawing.Imaging.ImageFormat.Gif);
but when i read data from mstream, it is diffirent from the old one, it is not clearly then the old one, why?
|
|
|
|
|
I am using MSDE in C#, and I have a little problem. Sometimes, I create a connection object, and connection fails because the database is not running. The service is set to start automatically - what do I need to do to make it start for me ? SQLBuddy manages to start it, so there seems to be some step in code that I am missing.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
You said sometimes it fails.Usually I will reinstall it in these cases.
|
|
|
|
|
I assume it happens only at startup. If so, Put some delay in your application to let MSDE start first
Sanjay Sansanwal
www.sansanwal.com
|
|
|
|
|
has anyone used these products?
if so can they be used while tables are locked?
|
|
|
|
|
I'm converting a C++ application to C# (yes - I know, dumb thing to do). The issue I've run into is when I put text into a text box, in C++ I could just add a \n to get a new line. Now, in C# text boxes, I have to add \r\n to get the same result.
Why? Is there anyway I can get around this?
- Bruce
BRCKCC
|
|
|
|
|
you can use System.Environment.NewLine to add the new string.
|
|
|
|
|
I have an array of bytes -- created dynamically during program execution -- that make up the color bits of a bitmap image. Is there a way in C# to create a Bitmap object that uses this array as it's data? I'd like to be able to save this to a file as a bitmap and I haven't been able to find any kind of documentation for this. As a temporary solution, I'm copying the data pixel by pixel into the array, but this seems very ludicrous. I know in C++ I was able to put a bitmap header on the data and presto, instant bitmap. I'd love to be able to do something similar in C#. Someone please help!
Thanks in advance.
|
|
|
|
|
I recomand creating a new Bitmap object and set it's pixels with the SetPixel procedure
Bitmap bmp = new Bitmap(width, height);<br />
bmp.SetPixel(x, y, color);
Then you can do wathever you want with the object, even save it into the memory with the Save procedure
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
That's actually what I'm already doing (I had to have something working temporarily). But this is a very slow way of doing things and for the program I'm working on, speed really matters. Thanks for the suggestion, though
|
|
|
|
|
In C# you can lock the bitmap in memory and put the bytes under the header:
<br />
Bitmap bmp = new Bitmap(width, height);<br />
BitmapData bmpData = bmp.LockBits(new Rectangle(0,0, bmp.Width, bmp.Height), bmp.PixelFormat);<br />
<br />
Marshal.Copy( byteArray, 0, bmpData.Scan0, byteArray.Length );<br />
<br />
bmp.UnlockBits(bmpData);<br />
bmp.Save(fileName, imageFormat);<br />
|
|
|
|
|
I am writing a user control that encapsulates System.Windows.Forms.Control objects. In the paint event of my user control, I want to paint to my user control the graphics that would appear on the encapsulated control. I have tried:
Graphics cg = Graphics.FromHwnd(control.Handle);
and
Graphics cg = control.CreateGraphics();
then passing that Graphics object to the base paint event of my user control, but that doesn't work either. Can anyone help?
|
|
|
|
|
sortamusic wrote:
I want to paint to my user control the graphics that would appear on the encapsulated control.
A simple and dirty way to paint the graphics that apears on a control to another is to copy it with the BitBlt function :
[System.Runtime.InteropServices.DllImport("gdi32.dll")]<br />
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
Get the source and destination hDC from the graphics with (Graphics)g.GetHdc(); , call BitBlt and release the hDCs (Graphics)g.ReleaseHdc(hDC);
I hope you understand...
|
|
|
|
|
Thank you for your help! It has certainly put me in the right direction. I am still having a problem with it though. Instead of drawing the graphics of my underlying control, the graphics being painted are from a screen shot. Here is the code I am using:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
if (control != null)
{
Debug.WriteLine( "Drawing graphics of control: " + control.GetType().FullName );
//Get the source and destination hDC from the graphics with
//(Graphics)g.GetHdc();, call BitBlt and release the hDCs (Graphics)g.ReleaseHdc(hDC);
Graphics cg = control.CreateGraphics();
IntPtr hdcSrc = cg.GetHdc();
IntPtr hdcDest = g.GetHdc();
BitBlt(hdcDest, 0, 0, this.Width, this.Height, hdcSrc, 0, 0,
(int)BitBltConstants.SRCCOPY);
g.ReleaseHdc(hdcDest);
cg.ReleaseHdc(hdcSrc);
return;
}
}
The variable 'control' is the control that I want to grab the graphics from and paint onto the control using this paint method. One problem might be that the 'control' control is never visible to the user. The SRCCOPY constant has a value of 0x00CC0020. Any suggestions?
|
|
|
|
|
The bitblt method is a quck and dirty method witch may fail (your case). Because your control is never visible to the user it is never draw so it can not be copied (you goted an screen shot maybe because you gave the source X and Y (0,0) instead of the control location)
But from what I have read from your last post I sugest the followng method :
Let's say we have control A and want to render on control B everithing what is on control A. Control A is rendered by a procedure (usualy Paint). So you must intercep every OnPaint (or the rendering procedure) for control A and create a new PaintEventArgs based on the one recived by the procedure but with the Graphics changed (changing the graphics means suppling the graphics from control B) and then call the base with the new PaintEventArgs. Piece of cake
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
Asked that question before, but didn't get an answer to my question.
My problem is the following:
I'd like to make my standard Form completely transparent. To do that I set TransparencyKey property to BackColor:
private void Form1_Load(object sender, System.EventArgs e)
{
this.TransparencyKey = this.BackColor;
}
This way the form in fact becomes transparent, but when it is shown, there is a short black flicker until the background gets transparent. A way I figuered out to get rid of that is to set the BackColor to pure black, too:
this.BackColor = Color.Black;
But this is no satisfying solution. To figure out what was going on I replaced the OnPaintBackground function with my own one, which simply does nothing:
protected override void OnPaintBackground(PaintEventArgs e)
{
//empty
}
The result is a black background. This background doesn't appear when BackColor is set to black as mentioned above. Does this happen on your machines, too?
Thanks,
3Dizard
|
|
|
|