|
I am actually the one who wrote the code linked to on StackOverflow. If you read the notes on this post you will see that i originally wrote the code so that it only used one instance of the SpeechSynthesizer object.
This memory leak is very much a problem with the Speak or SpeakAsync method making the System.Speech object unusable in ANY project. If you run the code you will see it will QUICKLY cause Windows 7.0 (couple hours) to crash, and will cause Vista to crash after about 20 hours.
I have both versions of the code linked here in a forum post on the MSDN site.
http://social.msdn.microsoft.com/Forums/en-US/Offtopic/thread/ee7bd34f-20c2-4a75-9d5a-a0c5e7f1a9b2[^]
|
|
|
|
|
In a forms-based application, I would like to synchronize two RichTextBox controls so that one without a vertical scroll bar will scroll in synch with the other one (which has a vertical scroll bar). I.e., I want to be able to scroll both controls with one scroll bar.
Thanks for any suggestions,
Tom
P.S. I saw Karin Huber's article, but this is for WPF and Silverlight.
|
|
|
|
|
You can build a user control (or custom control), and handle the scroll event in another RichTextBox.
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:48am.
|
|
|
|
|
|
Hello,
How do I bin and zero fill excel data in both C# and excel? For example below is a list of data. I want to bin the data as integers
120.337
121.041
124.111
So the above should be. I want to say 0 of the date is not between a certain range as shown below
120-121= 120.337
121-122 =121.041
122-123 = 0
123-124 = 0
124-125 =124.111
|
|
|
|
|
Not sure what you mean but maybe something like this?
float RangeCheck(int lower, int upper, float value)
{
return ((value >= lower) && (value <= upper)) ? value : 0;
}
|
|
|
|
|
to make mass data entry easier so i can put my add form over the top of my excel sheet that contains the data i wish to enter. Is there a way to do the following without it minimizing both.
I understand the whole parent/child relationship of the forms but i was wondering if i could somehow do this because I have noticed programs like yahoo and so forth allow one form to be minimized while the other is maximized. Anyway here is what I'm trying...
private void Add_Button_Click(object sender, EventArgs e)
{
AddRecord addRecordForm = new AddRecord();
addRecordForm.Owner = this;
this.WindowState = FormWindowState.Minimized;
addRecordForm.ShowDialog(this);
this.WindowState = FormWindowState.Normal;
LoadData();
}
it minimizes but they both minimize instead of only the parent minimizing. i even tried putting in the constructor of the addrecord this.windowstate = formwindowstate.normal; and that had no effect.
|
|
|
|
|
I have tried compile example into .NET 2.0/3.0/3.5. I am using Windows 7 and didn't encounter your problem.
Did you accedently changed windowstato of your AddRecord Form?
|
|
|
|
|
tonyonlinux wrote: addRecordForm.Owner = this;
this.WindowState = FormWindowState.Minimized;
tonyonlinux wrote: it minimizes but they both minimize instead of only the parent minimizing
Does it really? Have you read the documentation[^]. Which is what you always should do when running into a problem.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
here's a working example:
In the Main form/container, on the add click do something like this:
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
Form2 f = new Form2();
f.Owner = this;
f.Show();
and on the LoadDataForm on the form closing event do something like this:
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
this.Owner.ShowInTaskbar = true;
this.Owner.WindowState = FormWindowState.Normal;
}
|
|
|
|
|
|
i was wondering something since the documentation states if the parent minimizes so does the child. (this was really my original question) because i had read this in the documentation BEFORE asking. is it possible to make the add form an owner of itself? i tried and it said I can't. Basically what I'm trying to achieve all of the parent/child stuff asside is the following. I guess what i want is the form to not be a child but simply another parent (per say).
I'm trying to make it where when i click on the addbutton up pops the addrecord form. and the main form minimizes. as documented and seen and so forth both will minimize. sure i can go down there and click on the thing to open it back up since the mainform is hidden until close(that part i like) but i want the child form return to normal state. is there some kinda method that you can use on the form like you do controls as form1.visible = false or hidden = true or something like that then change that on the form2 closeevent ?
|
|
|
|
|
sure you can trick the owner.
But a better solution is to not own the dataform. Something like:
private btn1Click(object sender, EventArgs e){
this.Hide();
DataForm df = new DataForm();
df.ShowDialog();
this.Show();
}
|
|
|
|
|
can a visual c# project connect to a remote mysql database and execute sql statements but w/out using mysql connector/net?
thanks in advance!
oh,and not just a yes/no answer...doh doh doh... if yes,how can you do it or if not, what is the simplest way of using mysql connector??
|
|
|
|
|
I'm not sure if you can do it without a MySQL connector, but using one is not that tough...
Download the MySQL data connector dll[^]. Register it in your project. Do something like below...
DataTable customerTable = new DataTable();
using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection("server=serverName;uid=userID;pwd=password;database=databaseName"))
{
string validationQuery = "SELECT * FROM Table WHERE Contact_ID = '" + actNumber + "';";
MySql.Data.MySqlClient.MySqlDataAdapter odda = new MySql.Data.MySqlClient.MySqlDataAdapter(validationQuery, conn);
odda.Fill(customerTable);
}
Hogan
|
|
|
|
|
You can use .NET Connector or ODBC connector. However if you do not want dll, .NET connector is open source and you get source file, and you can include it inside your project (Not add project to existing solution. yust .cs files) to remove dependency. However connecting to MS SQL server, a connector is build in into .NET framework
|
|
|
|
|
If you do not want MySql connector, Create an ODBC connection to the server - Use OdbcConnection in your project.
|
|
|
|
|
Hi All,
I am having problem while creating a custom event. My aim is to fire "DataChnaged" event whenever property "SetData" is called in following class defination.
The problem is, I am getting a null event in this line "DataChanged(this, e);". Anyone can help me understanding where I am wrong,
public class DataChangedEventArgs : EventArgs
{
private String _strArgVal = "";
public DataChangedEventArgs(String Value)
{
_strArgVal = Value;
}
}
public delegate void DataChangedEventHandler(object sender, DataChangedEventArgs e);
public class MyUserControlOne
{
String DataString = String.Empty;
public event DataChangedEventHandler DataChanged;
public MyUserControlOne()
{
DataString = "";
}
protected virtual void OnDataChanged(DataChangedEventArgs e)
{
DataChanged(this, e);
}
public String SetData
{
set
{
if (value != DataString)
{
OnDataChanged(new DataChangedEventArgs("Event Fired !!!"));
} DataString = value;
}
}
}
Calling code,
class Program
{
static void Main(string[] args)
{
MyUserControlOne o = new MyUserControlOne();
o.SetData = "ABC";
}
} Thanks,
Arindam D Tewary
|
|
|
|
|
first you need to check if OnDataChanged DataChanged is not null, then throw event. NullReferenceException is thrown, because there isn't any method subscribed to that eventmodified on Monday, March 1, 2010 1:40 PM
|
|
|
|
|
Thanks Saksida. As per your comment I noticed I have not provided any method which subscribes to the event. Now after I have written a "MyUserControlOne_DataChanged" method and its working nicely. Thank you very much for poiting me the mistake.
Now this is working nicely !
public class DataChangedEventArgs : EventArgs
{
private String _strArgVal = "";
public DataChangedEventArgs(String Value)
{
_strArgVal = Value;
}
}
public delegate void DataChangedEventHandler(object sender, DataChangedEventArgs e);
public class MyUserControlOne
{
String DataString = String.Empty;
private bool isEventWorking = false;
public event DataChangedEventHandler DataChanged;
public MyUserControlOne()
{
DataString = "";
this.DataChanged += new DataChangedEventHandler(MyUserControlOne_DataChanged);
}
protected void MyUserControlOne_DataChanged(object sender, DataChangedEventArgs e)
{
isEventWorking = true;
}
protected virtual void OnDataChanged(DataChangedEventArgs e)
{
DataChanged(this, e);
}
public String SetData
{
set
{
if (value != DataString)
{
OnDataChanged(new DataChangedEventArgs("Event Fired !!!"));
} DataString = value;
}
}
public bool EventWorking
{
get { return isEventWorking; }
}
}
calling code:
static void Main(string[] args)
{
MyUserControlOne o = new MyUserControlOne();
o.SetData = "ABC";
o.SetData = "ABCD";
o.SetData = "ABCD";
Console.WriteLine(o.EventWorking);
}
Thanks,
Arindam D Tewary
|
|
|
|
|
It is worth changing your code slightly to cope with the case when you have no handler - if you think about it not handling an event is not an error, it is perfectly normal. As such, it should not throw an exception.
Arindam Tewary wrote:
protected virtual void OnDataChanged(DataChangedEventArgs e)
{
DataChanged(this, e);
}
If you change your code to:
protected virtual void OnDataChanged(DataChangedEventArgs e)
{
EventHandler eh = DataChanged;
if (eh != null)
{
eh(this, e);
}
}
Then a potential source of run time exception is removed. (The load of "eh" is to handle the admittedly rare case when the handler is removed between the test and the execution)You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Hi OriginalGriff,
You are very much correct. I would be changing my code for sure. Thanks for your comment. Highly appreciate it. Thanks,
Arindam D Tewary
|
|
|
|
|
I would use:
protected virtual void OnDataChanged(DataChangedEventArgs e)
{
if (DataChanged != null)
DataChanged(this, e);
}
I think this way it is easier to read and not declaring new variable
|
|
|
|
|
No, what Griff gave you is the correct way to do things; there is a (probably small) probability that another thread could remove the content of the event between your code checking it for null, and your code using it. A local copy fixes that.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
tham. Now i see the problem. It was same example in a book i was reading. Maybe it is time to burn that book
|
|
|
|