|
I wonder if you need to cast it to be a textbox first ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for the suggestion, but it turns out the problem was something totally different.
The textbox in question is part of a CustomControl, and when I declared the public Attribute for Text I accidentally used the "new" keyword instead of "override". So, when I set .Text for the control, it was not actually setting the .Text for the TextBox part of the CustomControl like it was supposed to.
Turns out the code snippet I put in my original message DOES work just fine.
Thanks anyway for the response.
|
|
|
|
|
I want to create a program to relay stuff trough full screen applications,
Like multi media keyboard volume displays.
But i have no idea where to start could anyone point me in the right direction please.
|
|
|
|
|
Every C# application i make takes an excessive amount of RAM, like, the program I'm working on right now is about 500kb in size, but it takes almost 20MB ram.
I release every resource i use by flushing\closing\disposing\making it null and then calling the garbage collector but the app still takes like 17mb RAM...how can i make my program use less memory?
and another question: how can i use an exterior icon in my application, as in not compiling the program with it, but making the program use an exterior ICO file (thereby making it smaller)?.
|
|
|
|
|
It doesn't matter whether or not you load/unload resources. You could have a program that wrote Console.WriteLine and then Console.ReadLine and do nothing else, and the memory will still be taken up - the reason is because you still need to load the Runtime into memory.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
If you're judging by the "Memory" column in task manager, that isn't the amount of memory your app is using. To prove it to yourself, minimize your application and see how much "memory" your app is using. (Hint: the "memory" tab is how much Windows has allotted to your process, not how much your process is actually using)
p.s. you don't need to null references; the garbage collector will free them when there are no more references to the object, regardless of whether it's null.
|
|
|
|
|
Ok, and what about the icon question? do you happen to know how to do that?
|
|
|
|
|
Bitmap bitmap = new Bitmap("foo.ico");
IntPtr iconHandle = bitmap.GetHIcon();
Icon icon = Icon.FromHandle(iconHandle);
myForm.Icon = icon;
|
|
|
|
|
I assumed he meant the icon for the program itself, that is, the one you see in Windows. I don't get it tho, what's his program going to do if the file is not there ? I just don't see any benefit.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
First of all, it's not linear, any app will use the framework, writing simple apps doesn't give you an idea of how much RAM a complex app will use. I have written a couple of apps over several years that have major functionality in them, and their footprint is < 70 MB.
sharpiesharpie wrote: how can i make my program use less memory?
Write it in C++.
Remember, RAM is cheap nowadays.
sharpiesharpie wrote: (thereby making it smaller)?.
I don't think you can, and why would you want to ? Realistically, your exe would be, what, 10k smaller ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Not really, the icon is 158Kb...so without the icon, the program would be only about 300kb big instead of 500k...and anyway I'd like to know how to do it.
so...any help?
|
|
|
|
|
Make a smaller icon.
The thing is, your program can't ship without that icon. Nor can it ship without a 20 MB runtime. So, what's the point ?
Your code does not run to show your icon in Windows, Windows does that. So, there may be a way to set it up, but it has nothing to do with C#.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
sharpiesharpie wrote: the icon is 158Kb
Then it's not an icon, or you've got a HUGE number of icons in one file. Even at 32-bits deep, a 32x32 icon would be less than 5Kb!!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
sharpiesharpie wrote: Every C# application i make takes an excessive amount of RAM
You can't just rely on the "Mem Usage" column in Task Manager to determine this. Every .NET application is handed a bit of a managed memory allocation that is controlled by the .NET runtime (CLR) itself. The Mem Usage column in task manager doesn't know anything about this memory so you're not seeing accurate and reliable results. As other people have pointed out, there are far better ways to determine the actual amount of memory your application is using.
sharpiesharpie wrote: I release every resource i use by flushing\closing\disposing\making it null and then calling the garbage collector but the app still takes like 17mb RAM...how can i make my program use less memory?
All of this is fine, except for explicitly calling the garbage collector. You really don't want to do that unless you have a very good reason to. The biggest impact you will actually see from doing that is that your applications performance will suffer. Each time the garbage colletor runs, it effectively freezes the main thread of your application so it can determine what objects are still being referenced. You actually hurt performance by making too many GC calls, so it is generally best to let the GC decide on it's own when it should run.
sharpiesharpie wrote: how can i use an exterior icon in my application, as in not compiling the program with it, but making the program use an exterior ICO file (thereby making it smaller)?.
Not sure what the point for doing this actually is. A typical icon file is small, so embedding it as the main application icon (the normal way of doing things) shouldn't cause an issue.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Hi
Hope someone to show me how to make my coding work.
I had a procedure to generate the data into dataset. By using for loop, I can use responsewrite to show the data from dataset. When I bind the dataset on gridview. It shows the following error.
The event 'System.Web.UI.WebControls.BaseDataBoundControl.DataBound' can only appear on the left hand side of += or -=
There is my code:
DataSet ds = new DataSet();
ProjectOne.AuctionItems product = new ProjectOne.AuctionItems();
ds = product.ListAllProducts();
GridView1.DataSource = ds;
GridView1.DataBound();
Thanks.
Thanks.
|
|
|
|
|
DataBound is an event (as the error indicates) and no method, so you cannot call it. You probably wanted to write GridView1.DataBind(); .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
<br />
public partial class Form1 : Form<br />
{<br />
WebClient wc = new WebClient();<br />
public Form1()<br />
{<br />
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);<br />
InitializeComponent();<br />
}<br />
void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)<br />
{<br />
pb.Value=e.ProgressPercentage;<br />
<br />
}<br />
private void load_url(string url)<br />
{<br />
<br />
wc.DownloadData(url);<br />
<br />
}<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
load_url(tblink.Text);<br />
}<br />
<br />
}<br />
Hi,
The problem with the above code is that the following method is never called..
void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)<br />
{<br />
pb.Value=e.ProgressPercentage;<br />
<br />
}<br />
so the progressBar(pb) never get updated...Any Ideas what I am doing wrong?
I am using .Net Framework v 2.0
Regards
Q@!$3r
|
|
|
|
|
The documentation of the DownloadProgressChanged event clearly states that the event only occurs, if you execute the download asynchronously. Therefore, you need to replace wc.DownloadData(url); with wc.DownloadDataAsync(url); .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
|
I need to set table header forecolor and backcolor properties:
using System.Windows.Forms;
DataGridTableStyle tableStyle = new DataGridTableStyle();
Desktop td = new Desktop();
td.GetColors(tableStyle.HeaderForeColor,
tableStyle.HeaderBackColor);
However colors are not changed since it seems that parameters are passed by value.
Which is the best practice for change colors ?
I'll prefer to execute only one query in sql server and not to add additional properties, classes and structures to code.
Desktop class GetColors method contains:
public void GetColors(System.Drawing.Color foreColor,
System.Drawing.Color backColor) {
IDataReader tableReader = ExecReader(
"SELECT hforecol,hbackcol FROM desktop");
if (tableReader.Read()) {
foreColor = GetColor(tableReader.GetDecimal(0));
backColor = GetColor(tableReader.GetDecimal(1));
}
tableReader.Close();
}
Andrus
|
|
|
|
|
AndrusM wrote: it seems that parameters are passed by value.
Not generally true. Value types are passed by value and reference types are passed by reference.
If for example you have a int parameter, any changes to this parameter won't reflect outside the method.
If on the other hand the int is a field of some class assumably called IntHolder and a method has a parameter of this class, changes to the int field of an instance of the IntHolder class will reflect outside the method, because the object is passed by reference and the parameter points to the same object as a variable outside the method.
What will not reflect outside the method is the assignment of a new instance of the IntHolder class to the parameter. To circumvent the latter restriction and those mentioned for the value types, you can declare a parameter as ref or out . In short you could say that they cause a value type to be passed by reference and in case of a reference type imagine the reference to be passed by reference. For more information on the both keywords take a look at the docs.
In your specific case, I think the easiest would be passing the DataGridTableStyle instance to the GetColors method (is passed by reference) and assign the colors retrieved from the database to the corresponding properties.
public void GetColors(DataGridTableStyle tableStyle)
{
IDataReader tableReader = ExecReader("SELECT hforecol,hbackcol FROM desktop");
if (tableReader.Read())
{
tableStyle.HeaderForeColor = GetColor(tableReader.GetDecimal(0));
tableStyle.HeaderBackColor = GetColor(tableReader.GetDecimal(1));
}
tableReader.Close();
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you.
GetColors() method is located in my business object class.
DataGridTableStyle is in System.Windows.Forms
My business object class is compiled to separate dll . This dll cannot have reference to System.Windows.Forms since business object class must be independent of presentation.
BO class can be used with WebForms or WebServices. In tose classes other properties need to be initialized by GetColors.
So I cannot pass DataGridTableStyle object as business class method parameter.
I also tried out and ref properties but got compile time error that out and ref cannot be used with properties.
So I do'nt have any idea. It seems that I need to create 2 color methods in my BO only for getting colors back. Very inconvenient.
Andrus
|
|
|
|
|
AndrusM wrote: It seems that I need to create 2 color methods in my BO only for getting colors back.
There are still some other options.
1. You could return an array or some other collection with Color instances from the GetColor . The first item could be the fore color and the second the back color.
2. Define a custom struct or class that encapsulates two Color instances and return an object of this struct/class from the GetColor method. In my opinion better than option 1, because this way you can access the components of the return value by name and do not need to operate with anonymous fields of a collection.
3. Circumvent the compile error by passing in objects and afterwards assign them to the properties.
Color foreColor, backColor;
td.GetColors(out foreColor, out backColor);
tableStyle.HeaderForeColor = foreColor;
tableStyle.HeaderBackColor) = backColor;
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
What is the best Code Snippets Manager? I’ve found only this:
1) Total .NET SourceBook
http://www.fmsinc.com/dotnet/SourceBook/index.asp
2) Code Library .NET
http://myweb.hinet.net/home4/s630417/CodeLib.htm
3) Code Warehouse 2007
http://www.xcca.com
|
|
|
|
|
put imagelist control on your form and add images in it as you like. now come in to the list view property using smart tag. and go to the node which u add in listview and select your imageindex property value with ur imagelist control. you can only show images in listview over listnodes
|
|
|
|