|
check out the System.IO namespace, lots of useful classes such as FileStream for reading and writing files.
Another Post by NnamdiOnyeyiri l Website
|
|
|
|
|
First Thanks to Ista for you prevoise response, but it was only one level, I was looking for two fields.
I have two questions about loading a DDL. I have created these two simple examples as mine real need was harder to explain.
1) Lets say we have a Several UserControls and at least 15 of them have a State DropDownList control that is loaded from the database. So you have IA, Iowa, IL, Illonios, TX, Texas and so forth. I don't want to copy the code to open the database and load the DDL via binding on all 15 pages, I just want to code it once in a My_Utils.cs class. What is the best way to do this.
2) Now lets pretend that the above example was a create new user screen in which the data was not present so we could bind away and the user could pick what ever they wanted. This question is more from the edit side of the house. Lests say I edit a customer record where the database stores the TX code for Texas. When we edit the customer record how do you bind the States table to the DropDownList (as in questin 1 above) and then make the active record the TX record. I know how to do it loading it in a for loop and doing a If to check that values match. I was opening there might be a better way.
If you now where sample code is on the net could point me there. Thanks
Mike Stone
Kaskaskia COllege
|
|
|
|
|
combo1.DataSource = dsDataSet.Tables["States"].DefaultView;
combo1.DisplayMember = "State";
and if an id is associated
combo1.ValueMember = "ID";
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I've been browsing through DirectShow since reading some articles on here and I've found an interesting example under the DirectX9 sample directory:
...\Samples\C++\DirectShow\Filters\PushSource
"Set of three source filters that provide the following source data as a video stream:
CPushSourceBitmap - Single bitmap (loaded from current directory)
CPushSourceBitmapSet - Set of bitmaps (loaded from current directory)
CPushSourceDesktop - Copy of current desktop image (GDI only)"
As far as I can see it's a way of making one or more bitmaps emulate a video capture device, e.g. webcam. Scouting round the web, most people seem to do this sort of thing using the old AVI writer functions but this method seems more "up-to-date".
Has anyone got this sample working in C# (or even in VC++)?
Regards,
Andy
--------
God created the universe in 6 days and has been debugging ever since - welcome to the biggest ever beta test
|
|
|
|
|
whats the problem?
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Implementation
Sorry to be a bit thick but if I end up with a "pushsource.ax" file how to I go about using it in C#?
Best Regards,
Andy Beamish
------------
God created the universe in 6 days and has been debugging ever since - welcome to the biggest ever beta test
|
|
|
|
|
Oh wow! I really am thick...
I've registered the pushsource.ax and got it working in GraphEdit okay, it's starting to look easier all the time!
Now the tricky part: if I'm capturing stills from a webcam how can I feed them straight into the PushSource.ax rather than via a directory of files?
I'm sure I'll get there eventually but any suggestions would be appreciated
Best Regards,
Andy Beamish
------------
God created the universe in 6 days and has been debugging ever since - welcome to the biggest ever beta test
|
|
|
|
|
Hiya have just started learning C# so plz bare with me!!
Currently I output it like ( "User name is {0},username" );
But how do I format text output?? In c++, I would do something like
sprintf( buffer,"%-8.8s",username );
Is this type of formatting still valid in c# ??
Thanks.
|
|
|
|
|
Well, part of that. You cause use:
string.Format("{0:-8}","my string")
To format the text right justify at eight letters. If your string is longer than eight letters it will inlude the full length of the string.
Do a search for "Composite Formattting" and "Formatting Types". Those will help out. The MSDN documentation is a bit scattered about for "Format".
Rocky Moore <><
|
|
|
|
|
This should help you:
Formatting Overview[^]
Briefly the you specify format as (as provided by MSDN):
{index[,alignment][:formatString]}
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
I don't know how to declare the function,is fallowing right?
"
[DllImport("User32.dll")]<br />
private static extern int SendMessage(int hwnd,int msg,int wParam,int lParam); "
The underlined part i am not sure about;
At the same time,I hope to get am example include declare and using ;
Thanks!
|
|
|
|
|
I have written a small debug class so I can echo some statements to the ouput in VS and to a text file, using the StreamWriter class... The problem is, is that the text is never written to the file.
<br />
public class Debug<br />
{<br />
private StreamWriter _writer;<br />
private string path;<br />
<br />
public Debug(string path)<br />
{<br />
this.path = path;<br />
if( File.Exists(path) )<br />
_writer = File.AppendText(path)<br />
else<br />
_writer = File.Create(path);<br />
}<br />
<br />
public void WriteLine(string output)<br />
{<br />
string s = DateTime.Now + "\t" + output;<br />
<br />
System.Diagnostics.Debug.WriteLine(s);<br />
_writer.WriteLine(s);<br />
}<br />
}<br />
Now this is fairly bog standard code foe writing to a file, and even stranger is if i replace the WriteLine procedure with
<br />
public void WriteLine(string output)<br />
{<br />
string s = DateTime.Now + "\t" + output;<br />
System.Diagnostics.Debug.WriteLine(s);<br />
StreamWriter sw = File.AppendText(this.path);<br />
sw.WriteLine(s);<br />
sw.Close();<br />
}<br />
The text is written to the file fine. Can any shed light on this.... What dumbass thing I am I doing wrong?
|
|
|
|
|
Could it be because you are not explictly closing the stream in your original and maybe it is not being flushed?
Personally, in my logging I do not try keep the file open all the time, I use:
public void Write(string message, LoggingLevel level)
{
StreamWriter logFile=null;
lock(this)
{
try
{
logFile = new StreamWriter(fileName, true);
logFile.WriteLine(message);
logFile.Close();
}
catch(Exception)
{
if(logFile!=null)
logFile.Close();
}
}
if(isSystemDebugEnabled)
System.Diagnostics.Debug.WriteLine(s);
}
Rocky Moore <><
|
|
|
|
|
you have to fluch the stream.
Another Post by NnamdiOnyeyiri l Website
|
|
|
|
|
I'm trying to detect which cursor is currently shown on the screen, whether it is a wait cursor, arrow cursor, etc. Right now, the detection works perfectly EXCEPT that there are 3 cursors that i can't seem to detect sometimes - the hand cursor, horizontal and vertical splitter cursors.
The code i'm using is (with the GetCursorInfo API):
Info.Size = Marshal.SizeOf(Info.GetType());
GetCursorInfo(out Info);
if (Info.Cursor == Cursors.WaitCursor.Handle)
CurrentCursor = "Wait";
else if (Info.Cursor == Cursors.Default.Handle)
CurrentCursor = "Default";
else if (Info.Cursor == Cursors.AppStarting.Handle)
CurrentCursor = "Loading";
else if (Info.Cursor == Cursors.Hand.Handle)
CurrentCursor = "Hand";
....
After i did some tests, i noticed that when i convert the values to string, the two values of Info.Cursor and Cursors.Hand.Handle (along with the HSplit and VSplit values as well) do not tally and they tend to change over and over again almost every time i run my application again.
The tests were done by displaying the values of Info.Cursor and Cursors.Hand.Handle using codes like these:
MessageBox.Show(Info.Cursor.ToString());
MessageBox.Show(Cursors.Hand.Handle.ToString());
I did the tests mostly on Applications that have a weblink and also on web browsers. When using a web browser, the detection seems fine (for the hand cursor at least) but when i run an app that has a weblink somewhere and the hand cursor shows up, the values of Info.Cursor and Cursors.Hand.Handle are totally different.
Is there a way around this?
|
|
|
|
|
try using the .NET way, Cursor.Current
Another Post by NnamdiOnyeyiri l Website
|
|
|
|
|
Cursor.Current only detects the cursor within the form. I need to detect the cursor system-wide (i.e: both inside and outside the form).
|
|
|
|
|
How do I bind two table columns in a combo box with a '-' character separate the column without using concatenation method in my select SQL statement.
|
|
|
|
|
You dont hah ha
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Hi! I have the following code:
Stream stream = new FileStream("Form1.resx", FileMode.Open);
And the default directory for Form1 is in WindowsApplication1\Bin\Debug right?
But I want to use the resx in the WindowsApplication folder. How do I do this?
Please help this newbie.
"To teach is to learn twice"
|
|
|
|
|
Form's .resx file is an embedded resource. This means you can access it as shown below:
Assembly assembly = Assembly.GetEntryAssembly();
Stream stream = assembly.GetManifestResourceStream(
"WindowsApplication1.Form1.resx");
Alexandre Kojevnikov
MCAD charter member
Leuven, Belgium
|
|
|
|
|
What namespace will i add for this?
Thanks in advance!!
"To teach is to learn twice"
|
|
|
|
|
daljv wrote:
What namespace will i add for this?
Whichever you find appropriate. Just don't forget to update the parameter of GetManifestResourceStream() to "Namespace.Of.Form1.resx" .
Alexandre Kojevnikov
MCAD charter member
Leuven, Belgium
|
|
|
|
|
Hi! I used the follwing code:
Assembly assembly = Assembly.GetEntryAssembly();
Stream stream = assembly.GetManifestResourceStream("WindowsApplication7.Form1.resx");
ResourceReader a = new ResourceReader(stream);
IDictionaryEnumerator en = a.GetEnumerator();
en.MoveNext();
MessageBox.Show(en.Key.ToString());
MessageBox.Show(en.Value.ToString());
a.Close();
But I get an exception stating that:
An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
Additional information: Value cannot be null.
Why is this?
"To teach is to learn twice"
|
|
|
|
|
I probably misunderstood your question. You will need: System.Reflection and System.IO .
Alexandre Kojevnikov
MCAD charter member
Leuven, Belgium
|
|
|
|