|
methhoo wrote: Environment.GetFolderPath
whoops, forgot that part
glad to help
|
|
|
|
|
Pls see the code that I have used for setting the registry option when the user checks that option
void startup_Click(object sender, EventArgs e)<br />
{<br />
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");<br />
if (((MenuItem)sender).Checked)<br />
{<br />
key.DeleteValue("MyApp", false);<br />
((MenuItem)sender).Checked = false; <br />
}<br />
else<br />
{<br />
key.SetValue("MyApp", Application.ExecutablePath, RegistryValueKind.String);<br />
((MenuItem)sender).Checked = true;<br />
}<br />
}
methhoo wrote: How can I make the C# Setup Deployement project
I am not sure about this..
*jaans
|
|
|
|
|
So how do you handle the situation that; user uninstalls your program , but registry is still there. I mean wouldn't it cause an error every time windows starts, unless user knows how to delete this registry file.
I wish we could trigger (may be) an exe file when uninstall procedure begins, and do whatever stuff to do, after that uninstall would also delete this worker exe.file
|
|
|
|
|
Hi,
In my dataset I have numerous table adapters which I need to chose from at runtime.
I can create at runtime a text string for the adapter I need to use however I cannot use that string to construct the method. What I have done is create an array of tableadapters and then used the index of that array to contruct the method.
As the project grows, this is becoming a consuming exercise and I am surprised there isn't a better way.
Is there some way that you can select a tableadapter from the dataset at runtime using the string representation of the table adapter to select it with.
Thanks.
|
|
|
|
|
Glen Harvy,
I THINK its possible to do this with Reflection, but i've never used it, maybe a bit of googling/someone else might be able to confirm my post.
Regards,
Gareth.
|
|
|
|
|
Thanks for your response.
I've never used reflection either! <grunt> Guess I'll have to learn
I've tried googling (always do) and I'm sure it's there but what do I search on is the hard part
Glen Harvy
|
|
|
|
|
Hi All:
I've been trying to figure out how to print multiple copies of a page. This code is as close as I've been able to come, but I get odd results. The first time I try to print I specify 2 pages and I get 4 pages. Without leaving the program, the second time I try to print I specify 2 pages and I get one page printed with the second page on top of the first.
Any thoughts you have are very much appreciated!
Dale E. Moore
using System;<br />
using System.Drawing;<br />
using System.Drawing.Printing;<br />
using System.Windows.Forms;<br />
namespace MultipleCopies<br />
{<br />
public partial class Form2 : Form<br />
{<br />
private PrintDocument printDoc = new PrintDocument();<br />
private int copiesToPrint;<br />
public Form2()<br />
{<br />
InitializeComponent();<br />
}<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); <br />
PrintDialog dlg = new PrintDialog();<br />
dlg.PrinterSettings = new PrinterSettings();<br />
if (dlg.ShowDialog() == DialogResult.OK) {<br />
copiesToPrint = dlg.PrinterSettings.Copies;<br />
printDoc.Print(); <br />
}<br />
}<br />
private void printDoc_PrintPage(Object sender, PrintPageEventArgs e) {<br />
String textToPrint = "Printing " + copiesToPrint;<br />
Font printFont = new Font("Courier New", 12);<br />
int leftMargin = e.MarginBounds.Left;<br />
int topMargin = e.MarginBounds.Top;<br />
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, leftMargin, topMargin);<br />
copiesToPrint--;<br />
if (copiesToPrint < 1) <br />
e.HasMorePages = false;<br />
else <br />
e.HasMorePages = true;<br />
}<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.Run(new Form2());<br />
}<br />
}<br />
}
|
|
|
|
|
Shouldn't it be:
dlg.PrinterSettings.Copies = copiesToPrint;
Since you want to set the number of copies, not get the number.
Regards,
Gareth.
|
|
|
|
|
Thank you for the dialog; I fear I have been unclear in my specification! I want to print multiple copies of a multi-page document. So
printDoc.PrinterSettings.Copies = dlg.PrinterSettings.Copies; should set the copies and the number gets stuffed, but it seems to only control the first printing. And I've changed the source code, below, to identify the numberOfPages which also only seems to work on the first printing.
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace MultipleCopies
{
public partial class Form2 : Form
{
private PrintDocument printDoc = new PrintDocument();
private int numberOfPages;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
PrintDialog dlg = new PrintDialog();
dlg.PrinterSettings = new PrinterSettings();
if (dlg.ShowDialog() == DialogResult.OK) {
printDoc.PrinterSettings.Copies = dlg.PrinterSettings.Copies;
numberOfPages = 2;
printDoc.Print();
}
}
private void printDoc_PrintPage(Object sender, PrintPageEventArgs e)
{
String textToPrint = "Printing copies " + printDoc.PrinterSettings.Copies
+ ", pages " + numberOfPages;
Font printFont = new Font("Courier New", 12);
int leftMargin = e.MarginBounds.Left;
int topMargin = e.MarginBounds.Top;
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black,
leftMargin, topMargin);
numberOfPages--;
if (numberOfPages < 1)
e.HasMorePages = false;
else
e.HasMorePages = true;
}
[STAThread]
static void Main()
{
Application.Run(new Form2());
}
}
}
|
|
|
|
|
Thanks to your help I was able to blow away some of the fog in my mind and realize I should be handling my variables differently. The following code has resolved my problem.
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace MultipleCopies
{
public partial class Form2 : Form
{
private PrintDocument printDoc;
private int numberOfPages;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
printDoc = new PrintDocument();
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
PrintDialog dlg = new PrintDialog();
dlg.PrinterSettings = new PrinterSettings();
if (dlg.ShowDialog() == DialogResult.OK) {
printDoc.PrinterSettings.Copies = dlg.PrinterSettings.Copies;
numberOfPages = 2;
printDoc.Print();
}
}
private void printDoc_PrintPage(Object sender, PrintPageEventArgs e)
{
String textToPrint = "Printing copies " + printDoc.PrinterSettings.Copies
+ ", pages " + numberOfPages;
Font printFont = new Font("Courier New", 12);
int leftMargin = e.MarginBounds.Left;
int topMargin = e.MarginBounds.Top;
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black,
leftMargin, topMargin);
numberOfPages--;
if (numberOfPages < 1)
e.HasMorePages = false;
else
e.HasMorePages = true;
}
[STAThread]
static void Main()
{
Application.Run(new Form2());
}
}
}
|
|
|
|
|
I need some assistance in tracking down why my code will not run as a service.
I have been hacking at this for over two weeks on and off with no real progress.
I need to use an old dll to access data.
When I call it from a console app, it works just fine.
Here is a snip of the code that works...
[DllImport("C:\\Program Files\\Omaha_Steaks_NUCAS_Reader\\libhab2.dll")]
public static extern int HABRSCI(string RSCI1, string RSCI2, string RSCI3, string RSCI4, string RSCI5);
static void Main()
{
try
{
//Create Variables for Host Access string
string resbuff = new string(' ', 80);
string reascode = "0000";
HABRSCI("0000", "01", "nucas.txt\0", resbuff, reascode);
}
catch (Exception ex)
{
string zzzz = ex.Message;
}
}
I rewrote as a Service, everything works except the dll call, it just acts as it was never called at all.
Here are some snips from my Service code....
//Set up usage of the .dll for Host Access
[DllImport("C:\\Program Files\\OS_NUCAS_Reader\\libhab2.dll",EntryPoint = "HABRSCI")]
public static extern int HABRSCI(string RSCI1, string RSCI2, string RSCI3, string RSCI4, string RSCI5);
and later, inside of a timer event..
try
{
//Create Variables for Host Access string
string resbuff = new string(' ', 80);
string reascode = "0000";
HABRSCI("0000", "01", "nucas.txt\0", resbuff, reascode);
}
catch (Exception ex)
{
}
This is just ignored!!!
I know the code executes around it, I have even added lines to write to the Event log just before and after the call.
If it works, a text file is created and a records is added to a log file maintained by the dll. none of these are happening so it apears that it ignores the call to the dll when running as Service.
Any assistance would be much appreciated.
Thanks,
Don
|
|
|
|
|
Hi,
I suggest you gather all information to find out what goes wrong, so:
1.
make sure you create a log file, and append all significant progress/trace info to it,
one line at a time.
2.
don't ignore exceptions
catch (Exception ex) {string zzzz = ex.Message;} and catch (Exception ex) {}
don't make sense since you are not doing anything with the exception's information.
Furthermore, you should always use Exception.ToString() keeping all the details.
3.
Make sure your app has an overall try-catch on top of your regular exception processing, so
even if you miss a local exception, you still catch it at the top level. You should apply
this to your main thread (the static main method), as to every thread you create.
4.
check and log all return values
public static extern int HABRSCI(...) promises a result, so store it in an int
and look at it. Maybe it is a status, with some negative value indicating a specific error.
5.
don't trust defaults for P/Invoke; I don't care to remember what calling convention is used,
I specify it explicitly on both sides (managed and unmanaged); example:
[DllImport("Winmm.dll", CallingConvention=CallingConvention.StdCall)]<br />
static extern int sndPlaySound(IntPtr buffer, int dwFlags);
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Luc
Good suggestions all.
I may have edited out too much when posting the code...
Anyway, I have run this with lines just before and after the HABRSCI call logging to an eventlog so I know it is getting to this line.
As to exceptions, they never come into play, no errors are happening (I have logging events in those sections also, never happen)
I can watch the app run by monitoring the lines being added to the event log, it loops every three minutes (current setting) and does several things, but the .dll never responds.
I did test it by adding code to return an int, but that always stays at zero in the Service (= no result) but returns either 4,8, or 16 in the Console version (indicates type of response collected by .dll)
If the .dll works, it generates a small text file with result data AND adds a 65 char line record to a text file in the local folder with status and timestamp information. This happens in the console version but not in the service version.
I will try the explicit call in #5 above to see if that helps.
Thanks,
Don
|
|
|
|
|
Hi Don,
some more ideas:
1.
if you have the source of the unmanaged code, you can add logging there too.
what I typically do is make it such that the unmanaged code logs to the managed world,
using a delegate (which becomes a function pointer).
2.
if the DLL has a simpler function somewhere, try that one first; or if you have the source,
add a simple function and try it (e.g. something that takes two ints and returns the product).
Success here proves you are accessing the DLL, and doing some P/Invoke correctly.
3.
I was a little surprised by the explicit NULL char in one of the args; if you try to get
a double NULL to the unmanaged world, I am not sure the marshaling will do that for you.
4.
if the unmanaged code throws an exception, it might just kill the thread without you noticing
(depending on which timer you use, you may get a separate thread).
You said "as if the function was not called", does the code return well from the unmanaged function, i.e. does the next (log) line get executed?
5.
If everything else fails my best guess is the unmanaged code executes but fails maybe
because there is no user, hence no "My Documents" and the like. Good error trapping should
catch that.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Luc,
Thanks for sparking an idea that did fix prt of the problem.
Your #5 comment did the trick (the "My Documents" bit!)
It appears that while it is running as a console app, any file calls are, unless otherwise directed, sent to the folder where the .exe file is.
In my case, to make this old .dll work, there MUST be a .cfg configuration file AND a file name reference .txt file in the same folder as the libhab2.dll.
As an console app, those were placed there by the installer.
I guess I assumed that this was the case with a Service also.
NOT.....!
All calls are sent to the C:\WINNT\System32 folder.
I placed copies of the .cfg and .txt (the .dll was alredy there) in there and it works!
Now I just have to figure how to redirect the "local" folder of a system login. (I guess I could leave the files in system32 but that feels wrong somehow!)
Error trapping did not help because the .dll just returned with a Zero and no other information. It had been writing to it's own log file, but I did not see it because I was expecting to to be created and added to in the C:\Program Files\OSNUCASReader folder, not C:\WINNT\System32.
If I had done a global search of my HD looking for "hafelog.log", I would have saved a week of hairpulling!
The log only had a line like this:
"20080116115428 23KDGWDLOG F_Dialog e 00085370Internal processing error encountered during routine operations. "
BUT, it would have let me know that the .dll was being called.
I just was not thinking about the System32 folder (too many trees to see the forest I guess)
Anyway, thanks for the suggestions and the spark to get me moving forward.
Don
|
|
|
|
|
Hi Don,
glad to be able to help.
yeah, I don't hesitate searching the whole C: drive for a file...; all too often something
gets stored in strange places.
Member 4372837 wrote: "20080116115428 23KDGWDLOG F_Dialog e 00085370Internal processing error encountered during routine operations. "
not the most useful message...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi.
I am having some trouble with a tab control I am writing. I have a user control that contains a class derived from tabcontrol, and also a class that derives from tabpage. I also have a method that adds a tab:
public void AddTab()
{
PictureTab a_picTab = new PictureTab("Test Title");
this.TabPages.Add(a_picTab);
this.m_pictureTabList.Add(a_picTab);
this.Dock = DockStyle.Fill;
}
When called in the constructor this creates a tab correctly, however when called later on (from a gui requesting add tab) there is no tab added. I am sure this is a simple silly fault but if anyone has any suggestions they would be much appreciated.
Thanks
Dan
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
DanB1983 wrote: there is no tab added.
Really? It's not in the TabPages collection or it is in the collection but it is not visible?
DanB1983 wrote: When called in the constructor this creates a tab correctly,
Perhaps there is something in the constructor, after it is called that is required?
And of course, have you read the documentation?
led mike
|
|
|
|
|
Oops sorry wasn't very clear there. It is in the tabpages collection but not visible.
The code for construction and add tab does the same:
public TabPictureBox()
{
AddTab();
}
public void AddTab()
{
PictureTab a_picTab = new PictureTab("Test Title");
this.TabPages.Add(a_picTab);
this.m_pictureTabList.Add(a_picTab);
this.Dock = DockStyle.Fill;
}
So when creating the object I add one tab, then when I wish to add another tab the collection is updated
but the tab is not visible. I have consulted the msdn documentation and added a tab according to that.
Thanks
Dan
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
Well I just did this and it works so that makes me think the problem might be in your PictureTab
private void addTab()
{
string stext = string.Format("Tab {0}", tabControl1.TabPages.Count + 1);
TabPage newPage = new TabPage(stext);
tabControl1.TabPages.Add(newPage);
}
led mike
|
|
|
|
|
Hey, thanks for your help.
I think the problem may be higher up as that code snippet does the same for me as adding my custom tab. If you could have a look at the following code I would be grateful. I haven't worked much with creating user controls so am pretty sure it is a simple error some where.
Thanks
Dan
public partial class TabbedPanelPictureBox : UserControl
{
TabPictureBox m_tabPbx;
public TabbedPanelPictureBox()
{
m_tabPbx = new TabPictureBox(); //this will call TabPictureBox::AddTab()
this.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.Controls.Add(m_tabPbx);
this.Dock = DockStyle.Fill;
}
private void TabbedPanelPictureBox_Load(object sender, EventArgs e)
{
}
public void AddTab()
{
m_tabPbx.AddTab(); //this will also call TabPictureBox::AddTab()
}
}
public class TabPictureBox : System.Windows.Forms.TabControl
{
private List<picturetab> m_pictureTabList = new List<picturetab>();
public TabPictureBox()
{
AddTab(); //Calls AddTab() and works
}
public void AddTab() //Doesnt appear to work outside of constructor
//even when just creating a normal TabPage
{
//PictureTab a_picTab = new PictureTab("Test Title");
TabPage a_picTab = new TabPage("Test Title");
this.TabPages.Add(a_picTab);
//this.m_pictureTabList.Add(a_picTab);
this.Dock = DockStyle.Fill;
}
}
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
What version of .NET and Visual Studio are you using? I am on 2005 .NET 2.0 and the first line of code in a UserControl constructor is
InitializeComponent();
So I added your PictureTab class to my test app and the tabs add just fine in response to a toolstrip button click that I have on my form. I did comment out this.Dock = DockStyle.Fill; From the AddTab method as well as the constructor. It should not be in AddTab to begin with and I am not using the control in .Fill mode anyway.
led mike
|
|
|
|
|
Hey.
I am using VS2008 and .NET 3.5
Yeah I had missed InitializeComponent() so have added that but am still having no luck.
The control is in a dll and is referenced in my gui project then instantiated like this:
<code>private void C_GmaGui_Load(object sender, EventArgs e)
{
//Set the main panel to be from where it starts to the edges of the screen
/*SetControlSize(mainPanel, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - mainPanel.Left,
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom - mainPanel.Top);*/
SetControlSize(panelMain, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - panelMain.Left,
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom - panelMain.Top);
this.tabbedPanelPictureBox1 = new TabbedPanelPictureBox.TabbedPanelPictureBox();
SetControlSize(this.tabbedPanelPictureBox1,
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - this.tabbedPanelPictureBox1.Left,
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom - this.tabbedPanelPictureBox1.Top);
//ClearOffScreenBitmap();
//DrawOffScreenBitmapToScreen();
}</code>
This creates the component fine and adds the first tab. However when this bit of code is called:
private void addTabToolStripMenuItem_Click(object sender, EventArgs e)
{
this.tabbedPanelPictureBox1.AddTab();
}
no tab is added. Just to be clear the code in the tabbedpanelpicturebox control is now:
public partial class TabbedPanelPictureBox : UserControl
{
TabPictureBox m_tabPbx;
public TabbedPanelPictureBox()
{
InitializeComponent();
m_tabPbx = new TabPictureBox();
this.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.Controls.Add(m_tabPbx);
this.Dock = DockStyle.Fill;
}
private void TabbedPanelPictureBox_Load(object sender, EventArgs e)
{
}
public void AddTab()
{
m_tabPbx.AddTab();
}
}
and
public class TabPictureBox : System.Windows.Forms.TabControl
{
private List<PictureTab> m_pictureTabList = new List<PictureTab>();
public TabPictureBox()
{
AddTab();
}
public void AddTab()
{
//PictureTab a_picTab = new PictureTab("Test Title");
TabPage a_picTab = new TabPage("Test Title");
this.TabPages.Add(a_picTab);
//this.m_pictureTabList.Add(a_picTab);
//this.Dock = DockStyle.Fill;
}
}
I will try building it under VS2005 and .NET 2.0
Thanks
Dan
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
Hi Guru's and Genii
I'm totally stuck here and now I'm clutching at straws.
What I want to do is use a WPF application in C# to place hooks on global low level system events and override some of them.
That's so NOT going to work... Why can't MS see that we need access to these things to expand the UI / UX of Windows?
Anyway, my last ditch attempt at a workaround, before throwing out my 3rd Yr Degree project was to 'cheat'.
I had the idea of a full screen and topmost transparent window. That would obviously allow mouse clicks, events, scrolling typing etc.. to happen to what ever windows / os is running.
However, I need to be able to have my 'invisible' application detect some of these events and perform different things to what the UI of Vista would normally do. I.e. have MY invisible app grab the event and not allow it to 'drop through'
Does anyone please have any ideas.. otherwise I think I'm going to fail my degree... arrgghhh!!!
Grrr.... WHY CAN'T MS GIVE US MANAGED CODE ACCESS TO LOW LEVEL GLOBAL SYSTEM EVENTS??? i.e. HOW windows flick WORKS???
Meh.
|
|
|
|
|
I know nothing about your question but i have heard that you will get to view/change ms code with next .net version
dont know how true it is....but wish it is true.
|
|
|
|
|