|
Use the Singleton pattern. Create a static member variable in your form where you keep an instance of your form.
Add a static method to your form class called "GetInstance" (or whatever you like). In that method check to see if your static variable contains an instance of the form. If it doesn't, put one in there (using new).
Then return from GetInstance the form instance kept in your member variable.
This guarantees that as long as you always call "GetInstance" to get your form object (this will require discipline on your part) only one instance of a form will ever be created:
MyCustomForm myForm = MyCustomForm.GetInstance();
MyCustomForm myForm2 = MyCustomForm.GetInstance();
myForm.WindowState = Normal;
myForm.Activate();
This space for rent!
My Blog
|
|
|
|
|
What TypeCode does an int-Array have?
|
|
|
|
|
Here's my Problem:
I have a hashtable in which i save a TypeCode as the key and the fitting regular expression as the value.
So for System.TypeCode.Int32 it would be @"\-?\d".
But I also want to parse Numbers seperated by values . Therefore I need a TypeCode for integer/double-arrays or something like that
|
|
|
|
|
The typecode of an array is System.Typecode.Object .
This space for rent!
My Blog
|
|
|
|
|
|
HI,
I have looked at the api of the WM Format and Encoder 9.0. There is a good way to capture the whole monitor screen movements in the form of an avi file. I also read the example of Idael Cardoso about how do it.
But i have one extension to it. Basically i want to transfer the frames online. But here i cannot use the encoder broadcast mechanism. I have custom api for networking.
So my question being is there any way to capture the frames and send across the network thru Windows media format api or encoder api?
thanks
eligeti
|
|
|
|
|
I already opened a thread for that but I still don't have a clue how to simply get the X-Coordinates from the first connected Joystick.
Someone recommended me the Code on http://www.error-bank.com/microsoft.public.dotnet.languages.csharp/219796_Thread.aspx
but this Code is incomplete and I was not able to complete it yet. It's just to hard to understand it in order to complete the code.
|
|
|
|
|
Any Kind of help would be great.
|
|
|
|
|
Hi
I have some xml:
<code>
<build>
<usings>
<item>System.Threading</item>
<item>System.Drawing</item>
<item>System.Windows.Forms</item>
<item>System.Diagnostics</item>
<item>System.Microsoft.DirectX</item>
<item>D3D = Microsoft.DirectX.Direct3D</item>
</usings>
<references>
<item>System.dll</item>
<item>microsoft.directx.dll</item>
<item>microsoft.directx.direct3dx.dll</item>
<item>microsoft.directx.direct3dx.dll</item>
<item>system.data.dll</item>
<item>system.drawing.dll</item>
<item>system.windows.forms.dll</item>
<item>system.xml.dll</item>
</references>
</build>
</code>
How can I read that data from each of the items in the references?
This is some code I have at the moment:
<code>
XmlTextReader reader = null;
try
{
//Load the reader with the XML file.
reader = new XmlTextReader("test.xml");
//Parse the XML and display the text content of each of the elements.
while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.IsEmptyElement)
Console.WriteLine("<{0}/>", reader.Name);
else
{
Console.Write("<{0}> ", reader.Name);
reader.Read(); //Read the start tag.
if (reader.IsStartElement()) //Handle nested elements.
Console.Write("\r\n<{0}>", reader.Name);
Console.WriteLine(reader.ReadString()); //Read the text content of the element.
}
}
}
Console.ReadLine();
reader.ReadToDescendant("usings");
reader.
Console.WriteLine(reader.Name);
Console.ReadLine();
}
finally
{
if (reader != null)
reader.Close();
}
</code>
Thanks
|
|
|
|
|
I have developed a lot of c code and use c++ as the gui. So I down loaded Visual Studio 2005 beta version to find out a bit about c#. I was surprised that there is no windows.h file. Is this beause it is a beta version or is that the way it is with .NET?
|
|
|
|
|
You seem to have a wrong view on .Net and C#. C# has nothing to do with C or C++. But you can have managed C++ in the .Net world.
|
|
|
|
|
Is there no C in C#? I was hoping to use c# at the front end and C to do all the number crunching.
What will happen to my c/c++ code when I decide to move to .NET?
|
|
|
|
|
Have you read my post completely?
First of all there is managed C++ which is some kind of mix between C++ and the .Net world (never used it). You can also directly use C-dlls from C# (and from many of the other .Net languages too).
|
|
|
|
|
|
Thanks Dennis and Robert,
Will Visual Studio 2003.NET standard edition 'do' for me?
The 2005 beta edition does not have MFC in its templates window if I want to create a new project!
Thanks,
Mike
|
|
|
|
|
McSam wrote:
Will Visual Studio 2003.NET standard edition 'do' for me?
In terms of C/C++? I don't know. I primarily use C# and sometimes VB. Maybe you should ask that question on the Managed C++ board[^] (or the Visual C++ board[^] for that matter).
McSam wrote:
The 2005 beta edition does not have MFC in its templates window if I want to create a new project!
Please, don't get me wrong, but I'm a little bit confused why you insist on creating MFC applications with VS 2005. This product is mostly about .NET and you also haven't explained why you still have to create MFC applications. Maybe you should really give .NET a try and see if it works for you.
Best regards
Dennis
|
|
|
|
|
I am using VC++ V5.0, it is time to upgrade. .NET seems the only way to go? My projects so far do not involve the web or networks.
Regards,
Mike
|
|
|
|
|
McSam wrote:
I am using VC++ V5.0, it is time to upgrade. .NET seems the only way to go? My projects so far do not involve the web or networks.
No offense, but I think you're still missing the point what .NET is about. It has nothing to do with the web or networks in general. It's a technology which is in parts comparable to Java. Please have a look at MSDN .NET Framework Developer Center: Getting Started[^]. To further clarify it: MFC is a legacy technology from the .NET point of view.
Best regards
Dennis
|
|
|
|
|
rockmate wrote:
So I down loaded Visual Studio 2005 beta version to find out a bit about c#. I was surprised that there is no windows.h file.
I agree with Robert. C# is primarily about RAD with the .NET Framework and not about Win32 as long as there is a managed way to do it. There are no header files in C# anyway. I sometimes use the header files if I use P/Invokes and need some defines. Just download the Platform SDK[^] and remember that the Common Language Runtime (CLR)[^] defines its own data types (see Platform Invoke Data Types[^]).
Best regards
Dennis
|
|
|
|
|
Hi
I wish you a Joyful and Happy New Year.
I am new to c# , so I dont know how to do.
ie,
My requirement exactly is :
Now My program reads a schema file( with field names name(string), salary(decimal)).
They are read and the values are inserted to the fields automatically.Like
(john1,john2,john3,..etc. for name)(2000, 2001,2002 , ..etc for salary).They are written into a xml file(say for instance salaryemp.xml).
this is what happens to my program.
Now what I have to do , I should be able to read another xml file( say for instance corporate.xml) which also has this name field with many original datas( like james, george, munna,..etc. ). So my program should read these values and fed(insert) into salary.xml file(only the name field should get altered with the values of corporate.xml). the salary field should remain the same.
pls help me to do that .
Just give me a coding help.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;
using System.Xml.Schema;
namespace testdatagenerator
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtSchema;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtXml;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Data.DataSet dataSet1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.txtSchema = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.txtXml = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataSet1 = new System.Data.DataSet();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
this.SuspendLayout();
//
// txtSchema
//
this.txtSchema.Location = new System.Drawing.Point(232, 24);
this.txtSchema.Name = "txtSchema";
this.txtSchema.Size = new System.Drawing.Size(368, 20);
this.txtSchema.TabIndex = 0;
this.txtSchema.Text = "";
//
// button1
//
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button1.Location = new System.Drawing.Point(616, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Browse";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txtXml
//
this.txtXml.Location = new System.Drawing.Point(232, 64);
this.txtXml.Name = "txtXml";
this.txtXml.Size = new System.Drawing.Size(368, 20);
this.txtXml.TabIndex = 2;
this.txtXml.Text = "";
//
// button2
//
this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button2.Location = new System.Drawing.Point(616, 64);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 23);
this.button2.TabIndex = 3;
this.button2.Text = "Load";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button3.Location = new System.Drawing.Point(696, 64);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(64, 23);
this.button3.TabIndex = 4;
this.button3.Text = "Save";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.DataSource = this.dataSet1;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 120);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(776, 320);
this.dataGrid1.TabIndex = 5;
//
// dataSet1
//
this.dataSet1.DataSetName = "NewDataSet";
this.dataSet1.Locale = new System.Globalization.CultureInfo("en-US");
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(32, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(184, 23);
this.label1.TabIndex = 6;
this.label1.Text = "Enter the Xml Schema";
//
// label2
//
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(32, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(192, 23);
this.label2.TabIndex = 7;
this.label2.Text = "Enter the Xml file";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(808, 454);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.txtXml);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtSchema);
this.Name = "Form1";
this.Text = "TestDatagenerator";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "select schema file" ;
fdlg.InitialDirectory = @"c:\CDEV\testdatagenerator" ;
fdlg.Filter = "schema files(*.xsd) |*.xsd| all files(*.*) | *.*";
fdlg.FilterIndex = 2 ;
fdlg.RestoreDirectory = true ;
if(fdlg.ShowDialog() == DialogResult.OK)
{
txtSchema.Text = fdlg.FileName ;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
dataSet1.ReadXmlSchema(txtSchema.Text);
foreach (DataTable dTbl in dataSet1.Tables)
{
for(int j = 0; j <= 200; j++)
{
object[] oValues = new object[dTbl.Columns.Count];
int i = 0 ;
foreach (DataColumn dColmn in dTbl.Columns)
{
switch(dColmn.DataType.ToString())
{
case "System.String":
oValues[i] = (string) "Castle Hampers" + j;
break;
case "System.Int32":
oValues[i] = (int) 100 + j;
break;
case "System.DateTime":
oValues[i] = new DateTime(2004,01,30).AddDays(j * 1);
break;
case "System.Decimal":
oValues[i] = new Decimal(10000900.99) + j;
break;
case "System.Int16":
oValues[i] = (short) 32767 - j;
break;
case "System.Int64":
oValues[i] = (long) 400 - j;
break;
case "System.Double":
oValues[i] = (double) 888888 - j;
break;
case "System.Single":
oValues[i] = (float) 4.5f + j;
break;
}
i = i+1;
}
dTbl.Rows.Add(oValues);
}
}
}
private void button3_Click(object sender, System.EventArgs e)
{
dataSet1.WriteXml(txtXml.Text,XmlWriteMode.WriteSchema );
MessageBox.Show("Saved");
}
}
}
santhosh
|
|
|
|
|
I have .jpeg image with dimension(2000 * 1500), scanned with 200 DPI....When I check pixel color of some (x,y) in Photoshop and retrieve same pixel in GDI+ using bitmap.GetPixel(), I found the difference of 25+ in each color(R,G,B). And When I use some third party Image library (which is wrapper on .NET) gives approximately same color components as Photoshop.
so, Whats up!!!!
Any help regarding this would greatly be appriciated.
Regards.
MaulikCE
Life's a game, full of surprises!!
|
|
|
|
|
You probably have ICC profiles configured in Photoshop. ICC profiles are used to match colors on different devices. With GDI+ (namely, the System.Drawing members in the .NET BCL) you must explicitly state to use ICC profiles. You can do this, for one example, by passing true for the icm parameter of various Bitmap constructor overloads.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
while i just read int this forum abt statement related "using".
Its sumthing like using { graphis g = e.Graphics }
while i want to ask is there any keyword like using for replacing :
try
{
}
catch
{
}
finally
{
}
just like using replaces try{}finally{}
Regards
|
|
|
|
|
Using doesn't replace try/finally. Using ensures that the object you "use" is disposed (ie, IDisposable.Dispose() is called) as soon as the using block is exited. It also ensures that Dispose() is called properly when an exception is thrown that isn't handled within the using block.
Using only works on objects that implement IDisposable, IE:
<br />
using (Font myFont = new Font("Arial", 10.0f))<br />
{<br />
}
In answer to your question though: there is no shorthand syntax for try/catch/finally.
This space for rent!
My Blog
|
|
|
|
|
You might want to look at the IL for code using the using statement. When you compile the using construct is expanded to a try/finally (not a try/catch/finally, though):
using (Graphics g = Graphics.FromImage(img))
g.Clear(Color.White); Becomes
Graphics g = Graphics.FromImage(img);
try
{
g.Clear(Color.White);
}
finally
{
g.Dispose();
} Using ildasm.exe that ships with the .NET Framework SDK is handy for examing build outputs.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|