|
I wonder if there is a built in attribute in system.management which can access the status of the application. So far i have looked into the win32_Process namespace in root/cimv2 in WMI which may have only started or stopped values for the status attribute. Or i will need an explicit timer to poll the application?
|
|
|
|
|
Hi everyone,
I am trying to learn how to use dynamic controls with/by calling a class library (ButtonTest.cs) that is on a separte *.cs, that contains the properties that will set them from my main form (frmMain.cs). I am using windows forms, C#. The two codes for the two forms are as follows:
>>frmMain.cs<< Calling form
using System;
using System.Drawing;
using System.Collections;
using System.Component.Model;
using System.Windows.Forms;
using System.Data;
namespace Test
{
public frmMain()
{
InitializeComponent( );
ButtonProperties myTest = new ButtonProperties();
myTest.AddControl(new Button( ), new Point(5,5), new Size(75,75), "ButtonName", 0, "");
}
}
>>ButtonTest.cs<<
using System;
namespace Test
{
class ButtonProperties
{
public void AddControl(Control aControl, Point Location, Size Size, String strText, int TabIndex, string strName);
{
aControl.Location = Location;
aControl..Size = Size;
aControl.Text = strText;
aControl.TabIndex = TabIndex;
aControl.Name = strName;
this.Controls.Add(aControl);
}
}
}
Now the problem is that the "this.Controls.Add(aContol);" does not get returned and the button is not displayed. The error is as follows: "Test.ButtonProperties" does not contain a definition for Controls. Hmmm
Any and all help is truly appreciated.
MikeY
I can't be this stupid
|
|
|
|
|
Try adding the following to ButtonTest.cs:
using System.Windows.Forms;
|
|
|
|
|
Hi!
Trust the compiler, it's right.
Your class Test.ButtonProperties only has a single method and no attributes/properties.
You're calling "this.Controls.Add(aControl)", but your "this" (ButtonProperties instance) doesn't have a Controls property.
Perhaps you want to add it or derive ButtonProperties from a base class that has a Controls property.
Regards,
mav
|
|
|
|
|
Can this be done with both a textbox and richtextbox?
If you could please give me an example code.
Thanks
|
|
|
|
|
From what I've read it's not really possible to calculate the exact size of a string so that you can resize the textbox/richtextbox.
You can use Graphics.MeasureString() , but the results often are inaccurate. If you want to resize a RichTextBox I think you'd have to calculate the size of every substring that has a different font and then calculate the total size => immense effort to do it generically.
Regards,
mav
|
|
|
|
|
I have a windows form with a series of questions and multiple choice answers. The questions vary in size of text content. What is the best way to display text on a windows form if you have text content that varies in size? Can you draw it on screen instead of using a textbox or richtextbox? I've tried using a label but that doesn't work either.
The layout is like this:
Question:
...............................................
...............................................
...............................................
Choices:
...............................................
...............................................
...............................................
Answer & Explanation:
...............................................
...............................................
...............................................
Of course the form is scrollable in case the content gets too large.
Is there an easier way to do this?
|
|
|
|
|
Hi,
I want to make some changes to the row, -just before it is inserted..
Why is the following change not committed in the DB ???
-In debugger I can see the changes is OK!!, but in the DB the column is still Null.
* I fill some data into a dataTable.
* Using dataAdapter.Update(myTable);
protected static void RowUpdating(object sender, System.Data.SqlClient.SqlRowUpdatingEventArgs args)
{
if(args.StatementType == StatementType.Insert)
{
args.Row["CreatedBy"] = "Me";
}
}
|
|
|
|
|
Besinci wrote:
I want to make some changes to the row, -just before it is inserted..
Most likely because you are confusing the system--it's wanting to do an update, but by making an assignment to a field in the row, you're changing, or trying to change state, to an "Update".
Try using the RowUpdated instead. Although, this will result in a second write to the DB.
Which begs the question, why aren't you setting the field value when you create the data row to be inserted to begin with?
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Marc,
My previus sample was just to ilustrate the issue..
I allso tried updated. without success.
The issue is to catch diferent StatementTypes and do something to the row depending on the StatementType..
thx, Besinci
|
|
|
|
|
I have a Deployment Project being created in Visual Studio .NET 2003 to deploy a C# application.
I need to add some registry entries. However, I need to ask the user a question about what to put in the registry, so I show a custom dialog and assign the value of the edit box to a property "PROP1".
Now, in my registry value, I tried putting [PROP1] which does not work. This works if the registry entry is a string value. However, my entry is a DWORD value, so it doesn't like it.
How can I get the contents of PROP1 into a DWORD registry entry?
Thanks,
...Matt
|
|
|
|
|
Hey!
If I use a Stream (say MemoryStream), and writes data to this stream with a StreamWriter.
Then if I read data from the same stream at the same time, what happens to the read data?
If I have understood this right then no data is removed from the stream even if it has been read? I have to cal flush to remove all the data.
Is this right?
Is a regular stream from TCP (Network) or File stream working this way? If, how does they handle the readdata?
If I flush after I have read, then the writer could have written some new data that I haven’t readied yet.
Best Regards
SnowJim
|
|
|
|
|
No. A MemoryStream works prety much likle a Text file, but in memory. The data is not removed when read. It just moves the current position pointer to the next character to be read/written.
There is a buffered area in a Stream operation that temporarily holds data being written to the Stream. This data typically isn't written directly to the Stream immediately, kind of like a cache. In order to make sure that the changes (data written) to the stream are finally commited to the stream, you call the .Flush() method.
Now, a Stream only has ONE position pointer. If you write a bunch of data to the stream, you have to position the pointer (seek) to the beginning of the stream is you waht to read all that data. Now, if you don't reposition the pointer back to the end of the data, your next write will overwrite data that you have written, but not read yet.
I think what your doing can be done with methods that are more suited to the task, but I don't remember you posting a specific description of why your going through this trouble.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks!
The requirement on ower application is that we have to hand out a stream to the rest of the program.
This means that we have to write to that string and at the same time the other part of the program will have to be able to read from the stream using streamreader.
If we writes 1024 bytes to the stream every time(vary fast) then the other part of the program will probably not manage to keep up with the writer. There will probley be a small buffert all the time.
there by we cant clear the stream in any way.
Its strange that a stream really works like this? It should discard every byte it is reading.
I have seen that there is something cald peak (streamreader), that looks at the next byte with out discarding, this most mean that it will discard when reading from this stream?
What kind of stream is this? Can it really discard when reading?
I have tried to make my own stream, by using an Array List (with FIFO), this works, but the performance is to bad. I am placing one byte at one element, and when it’s readed on position 0 i remove it.
Will i have to do my own stream? And what buffert should I use? If I use a fixed byte array the buffert may run out before the reader have readed there data.
any proposition on my problem?
Best Regards
SnowJim
|
|
|
|
|
Streams do not discard the data as it is read, in general (although as Dave points out, the cursor must be manually positioned to move "backwards" in a stream).
StreamReaders are not streams (they provide utility methods to read streams), and the Peek method of StreamReader looks for the next byte in the stream without moving the cursor forward - that's all.
Is the requirement for your application actually to use a stream, or is it simply to provide some structure where values can be read/written, and where reading equates to removing the read value from the structure? What you seem to be describing is a Queue (not a stream type). The Queue class allows FIFO stacking of objects, which looks like what you want. Dequeued objects are physically removed from the list. Internally, it's a circular array.
The Queue class also provides a synchronized version for thread safety, if that's of any concern.
Alternately, you could develop your own Stream class, and make it do whatever you want.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Yes i understand that Streamwriters is not stream but tools to use on streams.
If the data is not discarded in an stream, then the data will eventualy become to big to store in memory. How does streams handle this?
If i use for example a stream with an TCP connection, and writes/reads on this stream, it will never be to big to fit in to the memory what i can se? and i am never using any flush, remove or souch.
Yes i have to provied a Stream from my software, streamreaders will be used on this streams later on. But Queue sounds good, I will probley have use of that in other softwares =)
Best Regards
SnowJim
|
|
|
|
|
As I understand it, a NetworkStream really just wraps a Socket. When Read (or BeginRead ) is called on the stream, it actually executes a Receive (or BeginReceive ) on the Socket . The NetworkStream itself does not appear to have an intrinsic buffer (byte[] ) the way a FileStream does.
NetworkStream actually does its work with unsafe code calls on a Socket below the surface.
If you need to periodically clear the stream, you could do so by just clearing the previously read portion of the stream or something, perhaps by reading the as-yet-unread portion of the buffer into memory, then creating a new stream with only that data (or as suggested before, implement your own stream for doing it), but either way, it may be important to synchronize your stream writing code and possibly your reading code when such an even occurs - you could lock the stream, clear the read portion, raise an event that it's been truncated, and unlock it.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Yes i have tryed to build my own stream there i use an ArrayList. Every Element is storing one byte, and this is not a good ide, ArrayList is to slow.
Then i thougt if i just use e memoryStream in side my stream, but then i have to synchronize as you say so i delet some readed date and during this deletion i will have to lock the memoryStream.
But if i have under stod it right i cant just delet some bytes in a memory stream, insted a vill have to use flush or somthing like that to remove the stream, and in this case all data will disipare.
Best Regards
SnowJim
|
|
|
|
|
As you have no-doubt discovered, storing an ArrayList of bytes is not a good idea (at least with the goal of reinventing a Stream ).
Flush does not cause all the data to disappear. It ensures that any bytes in the buffer are written to some device (at least that's the principal, although inheritors of Stream are free to implement it as they wish). In the case of MemoryStream , Flush is overridden to do nothing at all, since there is no known "device".
You're right. I don't know of any way to arbitrarily delete bytes in a stream, but as I suggested, you could just lock the stream, read the bytes you want to save from the stream (those not already read by the client) into a local byte[], then reinitialize the stream with those bytes and synchronize the reader and writer with the new position, length etc.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
dear friends,
i am writing a virtual keyboard and i want to know in what commands do i need to use in
order to write to an external text environment when a specific button is being clicked?
thank u 4 your time.
|
|
|
|
|
Define "external text environment".
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
notepad, word or any other editor.
like the microsoft virtual keyboard.
|
|
|
|
|
Can someone please help me with the following code?? I am basically trying to read from an Xml file and display text from that file into a textbox. Everything is ok except for trying to add the text to the textBox.Text i get an error and I don't know why. Are there any books that you would recommend for better understanding windows forms??
Error is:
WindowsApplication1.Form1.textBox1 denotes a field where a class was expected.
the line that causes the error is:
textBox1.Text = (reader.ReadString());
Here is the full code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Xml;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(48, 48);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(656, 224);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "text";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(760, 350);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
ProcessTest();
}
static void ProcessTest()
{
XmlTextReader reader = new XmlTextReader("c:\\testcj.xml");
while (reader.NodeType != XmlNodeType.EndElement && reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "question":
textBox1.Text = (reader.ReadString());
reader.Read();
break;
case "answer":
reader.Read();
break;
}
}
}
}
}
}
|
|
|
|
|
Hi,
Just take a look at the code, where you have defined a Static medthod ProcessTest...
in this method jour textbox1 control is out of scope.. -Jou can not use it in this way..
My suggestion to you as changes is...
ProcessTest(); ..should be removed from the main to be just after InitializeComponent();
static void ProcessTest() //change the keyword static to public.
-You should read more about 'member access modifiers' such as static private public ....
|
|
|
|
|
OMG, such a simple change and it works perfectly. Thanks a lot Besinci you have saved me a great deal of frustration. Do you know of any good reading material for working with windows forms?
Thanks again.
|
|
|
|
|