|
No problem, I learned a bit myself
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
If have to use the api
StartDocPrinter(handle,level,DOCINFO) in C#
but getlast error = can't find module
maybe there is a problem with the predefined structure DOCINFO.
Is there anyone that has already used this kind of function.
thanks
Filip.
|
|
|
|
|
when is use this code in VB6.0 it works
but when i try to import the functions via C# (dllimport) it doesn't work
//VB6.0 code
Option Explicit
Private Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
ByVal pDefault As Long) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As DOCINFO) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
pcWritten As Long) As Long
Private Sub Command1_Click()
Dim lhPrinter As Long
Dim lReturn As Long
Dim lpcWritten As Long
Dim lDoc As Long
Dim sWrittenData As String
Dim MyDocInfo As DOCINFO
lReturn = OpenPrinter(Printer.DeviceName, hPrinter, 0)
If lReturn = 0 Then
MsgBox "The Printer Name you typed wasn't recognized."
Exit Sub
End If
MyDocInfo.pDocName = "AAAAAA"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
Call StartPagePrinter(lhPrinter)
sWrittenData = "How's that for Magic !!!!" & vbFormFeed
lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
Len(sWrittenData), lpcWritten)
lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
End Sub
|
|
|
|
|
I'm looking for a tool that will instrument & then profile my C# components.
Does anyone know where I can find one?
I downloaded the "DevPartner Profiler" from Compuware, but it doesn't allow me to start the profiling.
Cheers,
Simon
X-5 452 rules.
|
|
|
|
|
Sorry, I got this to work.
Check it out here
Cheers,
Simon
X-5 452 rules.
|
|
|
|
|
How can I retrieved the File Icon and File Type like Windows Explorer
Thanks
BLaZiNiX
|
|
|
|
|
|
you don't know a method to make it like VC++
- Initialize the ImageList with SHGetFileInfo
- Make a GetShellIcon function return SHFILEINFO.iIcon
- Make a function to find the type of the file
I'm not sure but i think i can make it with a VC++ DLL and import it in C# !
|
|
|
|
|
Hi All,
I have a class called Database.cs which is called when my application is started up. This class then populates 2 arrays with data from my SQL database.
--Update--
I have also just noticed that once I move to another part of my application these arrays seem to vanish? am I going about this all the wrong way?
--Update--
Now I am trying to access these arrays and am running into problems.
I have the following code so far.
===============
Database sn = Database();
int j = sn.StaffNames.getUpperBound;
===============
Which doesn't work and if I change the first line to Database sn = new Database(); I think it is clearing my arrays?
Thanks,
|
|
|
|
|
Gavin_Mannion wrote:
int j = sn.StaffNames.getUpperBound;
Assuming StaffNames is the array; the name should be GetUpperBound (uppercase G), and it is a function that takes an integer specifying which dimension you want the upper bound from.
int j = sn.StaffNames.GetUpperBound(0);
That should give you the value you wanted, and yes the first line should be Database sn = new Database() assuming you are meaning to create a new instance of your Database class.
The only thing that could cause your arrays to be cleared is by either calling Clear() on the array, or by assigning a new array to it.
I have a feeling that it only seems that your arrays are being cleared though, so try the first fix and if that doesn't work reply back and I'll look into it further. More code would help as well, at least a generalized version of your code
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Okay the error message I get is the following
------------------
An unhandled exception of type 'System.NullReferenceException' occurred in LTBRMaintenance.exe
Additional information: Value null was found where an instance of an object was required
------------------
My code looks like this
===============
Database sn = new Database(); //Database is the name of my class
int h = sn.StaffNames.GetUpperBound(0); //StaffNames Array Name
===============
My Database.cs code looks like this
===============
public class Database
{
public string[] StaffNames;
public Database()
{
}
public void LoadStaff()
{
SqlConnection myConnection;
myConnection = new SqlConnection("server=127.0.0.1; uid=;pwd=;database=LondonTBR");
string sql = "ltbr_GetStaff 0";
// Connect to the SQL database using a "Stored Procedure"
SqlCommand myCommand;
myCommand = new SqlCommand(sql, myConnection);
myConnection.Open();
SqlDataReader dReader;
dReader = myCommand.ExecuteReader();
int j = 0;
int ArrayCount = 0;
//Set Array to correct size
if (dReader.Read())
{
ArrayCount = dReader.GetInt32(0);
StaffNames = new string[ArrayCount];
}
dReader.NextResult();
//Populate Array
while (dReader.Read())
{
StaffNames[j] = dReader.GetString(2) + ", " + dReader.GetString(1);
j = j + 1;
}
dReader.Close();
myConnection.Close();
myCommand.Dispose();
}
}
}
===============
If I step through the code the function LoadStaff() is called and does execute without any problems.
Let me know if you spot something I am doing wrong here
Thanks,
|
|
|
|
|
When is the LoadStaff() function called?
In the first code block you create the Database object then immediately try to read the StaffNames without calling the Load.
If you will always be calling LoadStaff when you create a Database object you should place a call to LoadStaff() in the constructor for the Database class.
If you won't be calling LoadStaff everytime then you should create a new StaffNames array.
public Database() {
LoadStaff();
} or
public Database() {
StaffNames = new string[0]
} HTH,
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
I have tried that way and it does work but my idea was that I call the LoadStaff() function when my application starts and then I do not need to access the database again until they try update something.
So as the SplashScreen is shown my application will load all the data needed into my arrays and then I can just read from them without accessing the database again.
something like this.
[code]
//SplashScreen_Load Code
Database LoadArrays = new Database();
InformationLabel.Text = "Loading Clinic Array.....";
LoadArrays.LoadClinics();
InformationLabel.Text = "Loading Staff Array.....";
LoadArrays.LoadStaff();
//So the 2 arrays are now populated
//The main menu now loads and they choose Edit User from the menu
//EditUser_Load Code
Database sn = new Database();
int uBound = sn.StaffNames.GetUpperBound(0);
[/code]
Now I haven't called the the load function again because I do not want to access the database again.
Am I going about this in all the wrong way?
Thanks,
PS:How do you change the bgColor where your code is displayed?
|
|
|
|
|
OK! Now I see where the problem is, you're confused about how properties work on a class.
I'm going to discuss a smaller class to keep the example simple.
public class MyClass {
public int data;
public MyClass() { }
} Simple right? The class has one public member, an integer called data.
Lets do some tests, and hopefully this will clear up your confusion.
public void Tests() {
MyClass foo = new MyClass();
foo.data = 1;
System.Console.WriteLine("foo = {0}", foo.data);
MyClass bar = new MyClass();
bar.data = 2;
System.Console.WriteLine("foo = {0}", foo.data);
System.Console.WriteLine("bar = {0}", bar.data);
} You'll notice that foo is still 1 while bar is 2. The reason is that the data is stored with each instance of the class (an instance is a creation of that type in memory). But what if you have a value that needs to change in ALL instances of your type? Enter the static field/property.
Simply make one change to the class definition public static int data .
Now re-run the tests; foo and bar will both be 2 now.
How does this apply to your circumstance? The arrays in your class are like data in the first example. Each array stays with that instance; so what happens when you create a new instance of your database class? A brand new instance of your arrays is created as well, this time without all the data.
You now have a couple different tactics you can use. The easiest solution is to put the static keyword in the declaration with your arrays. This makes your data 'stick' with the type. The other solution is to use the same instance over and over again; one way of doing this is through the Singleton pattern, but I'll let you learn about that when you feel ready.
Gavin_Mannion wrote:
PS:How do you change the bgColor where your code is displayed?
Secrets of the Jedi :-P Actually just do this with your code: <pre>code</pre>.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Well I feel like I have tangled myself in a web I just ain't going to be getting out of
Okay I have done as you said and I do understand everything that you have written down (minus the singleton thing but I don't wanna know )
I have made my arrays static but now I cannot access them from my form.
I get the following error message
C:\Documents and Settings\gavin\My Documents\Visual Studio Projects\LTBRMaintenance\EditUser.cs(202): Static member
'LTBRMaintenance.Database.StaffNames' cannot be accessed with an instance reference; qualify it with a type name instead
And they are no longer in my intellisense dropdown.
Here is what I have
public class Database
{
public static string[] StaffNames;
And in my EditUser_Load I have this
Database sn = new Database();
int uBound = sn.StaffNames.GetUpperBound(0);
StaffNames is where the blue squiggly is squatting at the moment.
Thanks for the help,
|
|
|
|
|
Whoops! (famous last words)
I forgot to mention this, when you have a static field you access it not by variablename.field, you access it by classname.field. So the last line should have been Database.StaffNames.GetUpperBound(0); .
Completely my fault.
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
YAY YAY YAY YAY ...
It worked ....
Thanks for the help maybe now I can get back on schedule with this project...
Cheers,
Gavin
|
|
|
|
|
Gavin_Mannion wrote:
maybe now I can get back on schedule with this project...
Good luck
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
If im developing a webservice how do i put up security so only authorized users will get access to it ?
/Mathias
|
|
|
|
|
Hi guys, I hope there is a simple explanation, or a simple workaround for this...
I need to capture both the click and double click events of a control. Depending on the event, the eventhandlers will do two totally different things.
The problem is, it seems that if you subscribe to both events, you ALWAYS get a click event before you get a doubleclick event.
Here's a little experiment I did when I got curious. Place a label on a form and set it's text property to "". Now add both a click and doubleclick event handler to the FORM. In the click event handler do the following
label1.Text="SingleMouseClick"
and in the doubleclick event handler...
label1.Text+="DoubleMouseClick"
Now, run the app and DOUBLE CLICK the form.
I get the label spittig out SingleMouseClickDoubleMouseClick indicating that the click event code ran first.
How can I get around this? I really want the events to be separate.
James, I know you're listening...you must have a plan as usual
Regards
Senkwe
Just another wannabe code junky
|
|
|
|
|
Senkwe Chanda wrote:
James, I know you're listening...you must have a plan as usual
LOL, yep you got me
The reason for having both events fire is to make the UI appear responsive, since the double-click time can be changed in the control panel you could have to wait up to a second or more before a click event would fire since it would have to wait to see if the second click ever occurred before firing the click event. whew, that was long winded :-P
Now for the fix.
Have your single click event handler enable a windows timer; have the double-click even disable that timer and do whatever you want.
Inside of the tick event in the windows timer is where you would code the single-click stuff.
You can obtain the maximum number of milliseconds that can elapse between clicks by reading the SystemInformation.DoubleClickTime property.
To be even more thorough you need to also ensure that the second click occurs within a rectangle of size SystemInformation.DoubleClickSize from the first click.
I highly recommend that you first set your double-click time way up; so you can see if this is going to be detrimental to the usability of your application.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Thanks again James, that should work beautifully.
Regards
Senkwe
Just another wannabe code junky
|
|
|
|
|
How to programmatically add a new control in Window Application in C# language?
|
|
|
|
|
MyControl c = new MyControl();
this.Controls.Add(c); Simple
I assume that this code is being executed in the forms class.
This is also how you add a control to a windows form normally.
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Thank you! I can add a new control but i can't set the properties for the control. this is my code:
TextBox tb = new TextBox();
this.Controls.Add(tb);
this.tb.Location = new System.Drawing.Point(150, 100);
this.tb.Multiline = true;
this.tb.Name = "textBox2";
this.tb.ReadOnly = false;
this.tb.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.tb.Size = new System.Drawing.Size(168, 32);
this.tb.TabIndex = 1;
this.tb.Text = "textBox1";
this.tb.Visible = false;
It gives errors. How to set the properties on the control?
|
|
|
|