|
WubbleU wrote: I put my lines of code right at the beginning of the main() method and that doesn't work.
Yes, but what exactly are you trying to do and what is the result?
Your program should look something like
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RotaForm());
}
You should be able to perform any other functionality before the three lines above to achieve the result you are after. However, it is somewhat difficult to understand exactly what you are trying to do, maybe if you post some of your code it will become clearer.
It's time for a new signature.
|
|
|
|
|
As far as I can tell, you want the project to be a Console project.
Perform your "before" stuff.
(Maybe wait for the user to press RETURN.)
Then call FreeConsole to remove the console window.
Then Run the Form.
[
System.Runtime.InteropServices.DllImportAttribute
(
"Kernel32"
,
SetLastError=true
,
EntryPoint="FreeConsole"
)
]
private static extern bool
API_FreeConsole() ;
/**
<summary>
Uses pinvoke to call the Windows FreeConsole method
</summary>
<returns>
The result of FreeConsole
</returns>
*/
public static bool
FreeConsole
(
)
{
return ( API_FreeConsole() ) ;
}
|
|
|
|
|
Hi, that's exactly what I needed! Thanks!
The problem I have now is that the form isn't closing when I hit the X button. Any ideas?
Thanks again!
|
|
|
|
|
Should I be running the form differently? Instead of Application.Run(..) ?
|
|
|
|
|
Hi,
On using data type StringBuilder, I find that sufficient instances of data type string is also getting
allocated!
I saw this information when I used VSTS profiler to understand memory allocation.
Isn't StringBuilder and string totally different data types or is it that
internally stringbuilder is nothing but of the type string?
My code is very straightforward
StringBuilder str = new StringBuilder;
for (int i =0; i < 10; i++)
{
str.Append("Net");
}
Regards,
NetQuestions
modified on Sunday, June 27, 2010 4:41 AM
|
|
|
|
|
StringBuilder is a totally diferrent type to string . It is there for efficiency purposes when building a string up from multiple parts (as per your loop). You need to decide when it is efficient to perform your string concatenation directly or through a StringBuilder . Many people suggest always using a StringBuilder , but I disagree. See this excellent article, by John Skeet, who really knows what he is doing http://www.yoda.arachsys.com/csharp/stringbuilder.html[^]
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
A StringBuilder is a mutable version of a string: when you keep appending, you are exhausting the space allocated for the StringBuilder, so it allocates another, bigger one. This happens repeatedly. Try allocating sufficient space to start with:
StringBuilder str = new StringBuilder(40);
The default is 16 bytes, so you will go over that quite soon!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
StringBuilder is different, but it is also a "build-in" type, not just a List<char> or something like that.
See here for in-depth information: Strings UNDOCUMENTED[^]
|
|
|
|
|
That article is wrong, there's nothing magic about StringBuilder. It just uses unsafe code to write to the built-in string data type. Your code could do that, too!
|
|
|
|
|
Interesting, I just assumed that the article would be right..
Now I looked with the Reflector of course and it appears that you are right instead. It just calls String.AppendInPlace which just uses some unsafe code.
|
|
|
|
|
"You can't observe a system without affecting it." -- Heisenberg's Uncertainty Principle
|
|
|
|
|
i need to print data with dot matrix printer(tvs msp 250 champion),and printer is connected with usb port not LPT port .i tried bellow code but
it is not working.Please suggest me better way .
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (DialogResult.OK == ofd.ShowDialog(this))
{
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
RawPrinterHelper.SendFileToPrinter(pd.PrinterSettings.PrinterName, ofd.FileName);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
string s = "Hello";
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, s);
}
}
public class RawPrinterHelper
{
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class DOCINFOA
{
[MarshalAs(UnmanagedType.LPStr)] public string pDocName;
[MarshalAs(UnmanagedType.LPStr)] public string pOutputFile;
[MarshalAs(UnmanagedType.LPStr)] public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint="OpenPrinterA", SetLastError=true, CharSet=CharSet.Ansi, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);
[DllImport("winspool.Drv", EntryPoint="ClosePrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint="StartDocPrinterA", SetLastError=true, CharSet=CharSet.Ansi, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static extern bool StartDocPrinter( IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);
[DllImport("winspool.Drv", EntryPoint="EndDocPrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint="StartPagePrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static extern bool StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint="EndPagePrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint="WritePrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten );
public static bool SendBytesToPrinter( string szPrinterName, IntPtr pBytes, Int32 dwCount)
{
Int32 dwError = 0, dwWritten = 0;
IntPtr hPrinter = new IntPtr(0);
DOCINFOA di = new DOCINFOA();
bool bSuccess = false;
di.pDocName = "My C#.NET RAW Document";
di.pDataType = "RAW";
if( OpenPrinter( szPrinterName.Normalize(), out hPrinter, IntPtr.Zero ) )
{
if( StartDocPrinter(hPrinter, 1, di) )
{
if( StartPagePrinter(hPrinter) )
{
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
if( bSuccess == false )
{
dwError = Marshal.GetLastWin32Error();
}
return bSuccess;
}
public static bool SendFileToPrinter( string szPrinterName, string szFileName )
{
FileStream fs = new FileStream(szFileName, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
Byte []bytes = new Byte[fs.Length];
bool bSuccess = false;
IntPtr pUnmanagedBytes = new IntPtr(0);
int nLength;
nLength = Convert.ToInt32(fs.Length);
bytes = br.ReadBytes( nLength );
pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
Marshal.FreeCoTaskMem(pUnmanagedBytes);
return bSuccess;
}
public static bool SendStringToPrinter(string szPrinterName, string szString)
{
IntPtr pBytes;
Int32 dwCount;
dwCount = szString.Length;
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
SendBytesToPrinter(szPrinterName, pBytes, dwCount);
Marshal.FreeCoTaskMem(pBytes);
return true;
}
}
Thanks & Regards,
Vishnu.
|
|
|
|
|
|
In a VS 2010 application I've been instructed to set a breakpoint and do a Quick Watch.
Can anyone tell me what a Quick Watch is and how you do it?
Thanks
Darrall
|
|
|
|
|
It's a way to watch a variable. When you hit the breakpoint, click Debug>QuickWatch... (or press Ctrl+D, Q ) and the QuickWatch dialog will appear which displays the value of the variable at that point.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks Pete
|
|
|
|
|
You're welcome.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
If you google for 'quick watch vs tutorial' youls find lots of people who can tell you this and more.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
|
hi
i am using to form in my application each form have a datagridview i want to transfer all the rows of one datagridview to other form datagridview how?
|
|
|
|
|
You can bound both the datagridview with the same datasource.
- Praveen
|
|
|
|
|
You can use this method to get the DatagridView DataSource.
public Form2(DataGridView dg)
{
InitializeComponent();
this.dataGridView1.DataSource = (DataTable)dg.DataSource;
}
|
|
|
|
|
i did't bound any datagrid to any datasource but i just added some rows to one datagrid and want to copy it to other form datagrid using the code
RegistrationForm rg = new RegistrationForm();
for (int i = 0; i < dataGridView2.Rows.Count-1; i++)
{
string[] values = { dataGridView2.Rows[i].Cells ["TestID"].Value.ToString(), dataGridView2.Rows[i].Cells["TestName"].Value.ToString(), dataGridView2.Rows[i].Cells["Charges"].Value.ToString(), dataGridView2.Rows[i].Cells["DeliveryDate"].Value.ToString() };
RegistrationForm.dataGridView1.Rows.Add(values);
his.Close();
|
|
|
|
|
Hey guys, I'm currently working on a windows application and I'm looking for some help from developers with this experience ... Currently it's being tested on a single computer after fixing all the bugs I'm planning to distribute it and my target is around 100 to 200 clients.
1- the best method for Creating an install file (other than visual studio built in one which I'm already using)
2- the best way to update the software (currently I have to reinstall it on the client's machine)
3- Any useful tips or articles on creating online update
4- currently I install SQL 2005 and attache my database, a friend of mine suggested SQL lite, which one is more efficient?
5- Security, I know it's almost impossible to guarantee this 100% but I'm looking to find the best method, adding CD keys which has to be confirmed online, having USB security keys, ... what do you recommend ?
Thanx guys, I'm looking forward to your tips and help and if you've got any articles regarding my question please share it with me cause I'm here to learn.
Regards,
K
|
|
|
|
|
Hi ,
I will Answer only About what I am Sure of ...
1- I use NSIS Script ( I love it )
4 - Sql2005 or Sqlite ?
SQL 2005 | Sqlite
------------------------------------------------------------------
Work on network (Server) | Work On Single Machine only ( embedded)
Hard to Deploy and Install | Copy and paste to Deploy
Up to 13.00 GB DataBase Size | Up to 2.00 GB Size
5 - I use SmartAssmbelly , and I never used Dongle before ( but you must take a look at www.safenet-inc.com[^])
I know nothing , I know nothing ...
|
|
|
|
|