|
1000?!?!??!
You can go with reflection:
Form form = (Form)Type.GetType("frmForm274").GetConstructor(new Type[0]).Invoke(new object[0]));
This code surely would create a new form everytime it is called. If you want to reuse the forms then:
private HashTable _formsHash = new HashTable();
public Form GetForm(strFormName){
if (!_formsHash.ContainsKey(strFormName)) {
_formsHash.Add(strFormName, Type.GetType(strFormName).GetConstructor(new Type[0]).Invoke(new object[0])));
}
return (Form)formsHash[strFormName];
}
But be careful that holding 1000 forms in memory might become a resource problem .
Just out of interest: What are those 1000 forms for? And who built them?
|
|
|
|
|
u get me wrong.
none of the forms at cache.
A solution consist of 12 seperate projects.
all forms count is about 1000.
there is one Main MDI Form Project, others are dll including forms.
I wanna add a toolbar to mdi form. But i would like to make it customize by user.
Each user can add his/her own short cut buttons to toolbar. Think i use Vs.net envoirenment with just "Standart" and "Layout" toolbar. I can add or remove buttons to each toolbar. In my project I wantto use just one toolbar. And user will choose his/her buttons. I add them to toolbar after login proses. When adding, i must add handler to all buttons. when user click a button, i have to create instance of form which belongs to that button then show.
|
|
|
|
|
Assuming all assemblies are already loaded the first line I posted will do the job:
Form form = (Form)Type.GetType("frmForm274").GetConstructor(new Type[0]).Invoke(new object[0]));
|
|
|
|
|
I'm a starter
How can I create a DBApplication on my Handheld?
How can i Connect to Sql server on my Lan network?
Rezak
Rojin to future
|
|
|
|
|
i can not know how to use App.config, how get value in that.
plz help me.
|
|
|
|
|
u can try
ConfigurationSettings.AppSettings["key"];
key is the string assigned to key tag in app.config file
rahul
|
|
|
|
|
If you are using Visual Studio, just right click on the project, click Add New Item and select Application Configuration File in the Utilities folder.
To create custom key/value pairs, just add something like this
<appSettings>
<add key="yourkey" value="yourvalue" />
</appSettings>
To use it from code, just do
System.Configuration.ConfigurationSettings.AppSettings["yourkey"];
Does this answer your question?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
thanks for ans.
i will try it.
|
|
|
|
|
i add App.config but my project can not found that show Exception NameSpace.
but i add that item. and the file is still in the project directory.
plz help me.
|
|
|
|
|
yes at last i am success. and thanks a lot to u.
|
|
|
|
|
Hi All,
Can any one give me the suitable functions for the following in c# :
1. To find first instance of a file name that matches the file specification like *.jpg? like _tfindfirst( ) function in vc++
2.To find the next name, if any, that matches the file specification? like _tfindfirst( ) function in VC++
3. To find the Sub Directory? like _A_SUBDIR( ) function in vc++
4. To ignore directory with . and .. ?
Thanks
|
|
|
|
|
Fore more file specification, please read FileInfo Help.
The subdirectory . and .. are ignored.
static FileInfo FindFile(string startDirectory, string extension)
{
DirectoryInfo di = new DirectoryInfo(startDirectory);
foreach(FileInfo fi in di.GetFiles())
{
if(fi.Extension.ToLower() == extension)
return fi;
}
return null;
}
static DirectoryInfo FindDirectory(string startDirectory, string dirNameToSearch)
{
DirectoryInfo di = new DirectoryInfo(startDirectory);
foreach(DirectoryInfo diSearch in di.GetDirectories())
{
if(diSearch.Name == dirNameToSearch)
return diSearch;
}
return null;
}
|
|
|
|
|
|
Dim strSQL
strSQL = "SELECT * FROM MyTable WHERE username = '" & _
Request.Form("username") & "'"
Set rs = db.Execute()
If rs.EOF Then
'Now do the insert
Else
Response.Write "Record exists"
End If
Can anybody help me using this code but in c#? I just need some kind of function that verify if I have already that name in database...but can't find the execute method in VB
Thanks
|
|
|
|
|
Are you talking about moving from ASP (not .NET) to C#?
cuz if, you are going to need to do a little more than this.
I can translate it to you but I don't think that this will work good.
string strSQL = "SELECT * FROM MyTable WHERE username = '" +<br />
Request.Form["username"] + "'";<br />
<br />
if (db.Execute().Rows.Count != 1)
else<br />
Response.Write ("Record exists");
good luck
|
|
|
|
|
Obviously parameters should be used. If not, people entering usernames like
' OR 1 = 1 --
can do funny things in your system. And this is such a simple way to hack a system that you can rest assured every single wannabee hacker out there knows it.
|
|
|
|
|
The purpose of this email to hopefully gain some insight into implementing a javascript scripting engine within an application framework for a .Net application. I am trying to figure out how to provide scripting capabilities to an application. I would like to provide a scripting engine that enables customers to implement their own business rules. I would like to run custom javascript scripts that handle certain events (OnBeforeUpdate or OnBeforeDelete or OnBeforeAdd, OnAfterAdd, etc...) on different business objects.
I would like to stick with javascript because it's a widely used scripting language. I am just not sure how to go about implementing a javascripting engine into my .Net application framework.
I took a look at Visual Studio for Applications (VSA) which seemed like a possible option but the fact that it's being discontinued has lead to me seek out other options. Again, I would like to stick with a javascript solution.
Any ideas on how to get started with this?
Any thoughts or guidance on this topic would be greatly appreciated. TIA!
Regards,
-Derek
-- modified at 21:57 Tuesday 23rd May, 2006
|
|
|
|
|
I am trying to calculate how many lines I can fit on a printed page using the following code. However, as you can see from the times i put against the trace statements, it is very slow indeed.
private void SetLinesPerPage()
{ this.pd = new PrintDocument();
Trace.WriteLine("SetLinesPerPage: Point 0"); // **TEST 21-May-2006 10:11:18.703
PageSettings ps = this.pd.DefaultPageSettings;
Trace.WriteLine(string.Format("{0}:{1}:{2}", ps.HardMarginX, ps.HardMarginY, ps.Bounds.Height));
// **TEST 21-May-2006 10:11:24.109
Graphics g = ps.PrinterSettings.CreateMeasurementGraphics();
Trace.WriteLine("SetLinesPerPage: Point 2"); // **TEST 21-May-2006 10:11:26.906
float pHeight = ps.PrintableArea.Height;
Trace.WriteLine("SetLinesPerPage: Point 3"); // **TEST 21-May-2006 10:11:28.578
this.pFont = new Font(pfName, pfSize);
float lHeight = this.pFont.GetHeight(g) * 1.5F;
this.pFont.Dispose();
this.linesPerPage = (int)(pHeight / lHeight) - 5;
Trace.WriteLine(string.Format("SetLinesPerPage: Set {0} lines per page", this.linesPerPage));
}
My printer is a USB connected device on another PC in my workgroup. It is online but I have not accessed it since I booted my machine. If I do access it before running this code, then it still takes the same elapsed time.
My systems are both Windows XP SP2 (fully up to date), both machines are running .NET V2 framework.
Please does anyone have any idea how I can descrese the elapsed time to perform this operation? (currently almost 10 seconds)
Thanks in advance.
|
|
|
|
|
hi
i want to use serial port in my project
how can i control the serial port with Visual Studio 2003
|
|
|
|
|
|
This is the source code from someone. I forgot the link to the right article.
This article is in VB.NET : http://www.codeproject.com/vb/net/Comport_made_simple.asp
but it was ported to C#.
using System;
using System.Runtime.InteropServices;
namespace Communication
{
public enum Parity
{
No = 0,
Odd,
Even,
Mark,
Space
}
public class CommPort
{
public int PortNum;
public int BaudRate;
public byte ByteSize;
private byte parity;
public byte StopBits;
public int ReadTimeout;
private int hComm = -1;
public bool Opened = false;
private const uint GENERIC_READ = 0x80000000;
private const uint GENERIC_WRITE = 0x40000000;
private const int OPEN_EXISTING = 3;
private const int INVALID_HANDLE_VALUE = -1;
public Parity Parity
{
get
{
switch (parity)
{
case 0:
return Parity.No;
case 1:
return Parity.Odd;
case 2:
return Parity.Even;
case 3:
return Parity.Mark;
case 4:
return Parity.Space;
default:
return Parity.No;
}
}
set { parity = (byte) value.GetHashCode(); }
}
[StructLayout(LayoutKind.Sequential)]
public struct DCB
{
public int DCBlength;
public int BaudRate;
public uint flags;
public ushort wReserved;
public ushort XonLim;
public ushort XoffLim;
public byte ByteSize;
public byte Parity;
public byte StopBits;
public char XonChar;
public char XoffChar;
public char ErrorChar;
public char EofChar;
public char EvtChar;
public ushort wReserved1;
}
[StructLayout(LayoutKind.Sequential)]
private struct COMMTIMEOUTS
{
public int ReadIntervalTimeout;
public int ReadTotalTimeoutMultiplier;
public int ReadTotalTimeoutConstant;
public int WriteTotalTimeoutMultiplier;
public int WriteTotalTimeoutConstant;
}
[StructLayout(LayoutKind.Sequential)]
private struct OVERLAPPED
{
public int Internal;
public int InternalHigh;
public int Offset;
public int OffsetHigh;
public int hEvent;
}
[DllImport("kernel32.dll")]
private static extern int CreateFile(
string lpFileName,
uint dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
int hTemplateFile
);
[DllImport("kernel32.dll")]
private static extern bool GetCommState(
int hFile,
ref DCB lpDCB
);
[DllImport("kernel32.dll")]
private static extern bool SetCommState(
int hFile,
ref DCB lpDCB
);
[DllImport("kernel32.dll")]
private static extern bool GetCommTimeouts(
int hFile,
ref COMMTIMEOUTS lpCommTimeouts
);
[DllImport("kernel32.dll")]
private static extern bool SetCommTimeouts(
int hFile,
ref COMMTIMEOUTS lpCommTimeouts
);
[DllImport("kernel32.dll")]
private static extern bool ReadFile(
int hFile,
byte[] lpBuffer,
int nNumberOfBytesToRead,
ref int lpNumberOfBytesRead,
ref OVERLAPPED lpOverlapped
);
[DllImport("kernel32.dll")]
private static extern bool WriteFile(
int hFile,
byte[] lpBuffer,
int nNumberOfBytesToWrite,
ref int lpNumberOfBytesWritten,
ref OVERLAPPED lpOverlapped
);
[DllImport("kernel32.dll")]
private static extern bool CloseHandle(
int hObject
);
public void Open()
{
DCB dcbCommPort = new DCB();
COMMTIMEOUTS ctoCommPort = new COMMTIMEOUTS();
hComm = CreateFile("COM" + PortNum, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if (hComm == INVALID_HANDLE_VALUE)
{
throw(new ApplicationException("Comm Port Can Not Be Opened"));
}
GetCommTimeouts(hComm, ref ctoCommPort);
ctoCommPort.ReadTotalTimeoutConstant = ReadTimeout;
ctoCommPort.ReadTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(hComm, ref ctoCommPort);
GetCommState(hComm, ref dcbCommPort);
dcbCommPort.BaudRate = BaudRate;
dcbCommPort.flags = 0;
dcbCommPort.flags |= 1;
if (Parity > 0)
{
dcbCommPort.flags |= 2;
}
dcbCommPort.Parity = parity;
dcbCommPort.ByteSize = ByteSize;
dcbCommPort.StopBits = StopBits;
if (!SetCommState(hComm, ref dcbCommPort))
{
throw new Exception("Comm Port Can Not Be Opened");
}
Opened = true;
}
public void Close()
{
if (hComm != INVALID_HANDLE_VALUE)
{
CloseHandle(hComm);
}
}
public byte[] Read(int NumBytes)
{
byte[] BufBytes;
byte[] OutBytes;
BufBytes = new byte[NumBytes];
if (hComm != INVALID_HANDLE_VALUE)
{
OVERLAPPED ovlCommPort = new OVERLAPPED();
int BytesRead = 0;
ReadFile(hComm, BufBytes, NumBytes, ref BytesRead, ref ovlCommPort);
OutBytes = new byte[BytesRead];
Array.Copy(BufBytes, OutBytes, BytesRead);
}
else
{
throw(new ApplicationException("Comm Port Not Open"));
}
return OutBytes;
}
public void Write(byte[] WriteBytes)
{
if (hComm != INVALID_HANDLE_VALUE)
{
OVERLAPPED ovlCommPort = new OVERLAPPED();
int BytesWritten = 0;
WriteFile(hComm, WriteBytes, WriteBytes.Length, ref BytesWritten, ref ovlCommPort);
}
else
{
throw(new ApplicationException("Comm Port Not Open"));
}
}
}
}
-- modified at 2:26 Wednesday 24th May, 2006
|
|
|
|
|
thank you guys
good coding
|
|
|
|
|
DA1 = new SqlDataAdapter("select * from tbmohasebe where tarikh = '"+comboBox1.Text +"'" , conn1);
DA1.Fill(dt1); //dt1 is Data table
dataGridView1.DataSource = dt1;
how can i hide some of columns in datatable that don't show in datagrid?
|
|
|
|
|
Use a specific select list...
select field1, field2, field3 from Table where blah blah blah...
Visit BoneSoft.com
|
|
|
|
|
Isn't this working ?
dt1.Columns.Remove("columnName");
------------------------------ "The Soapbox has been so ..."
|
|
|
|