|
You need to ask the main form thread to access the control for you.
For example, to add a text entry into MyListView, do something like the following:-
public class MyForm : System.Windows.Forms.Form {
private System.Windows.Forms.ListView MyListView;
...
[STAThread]
static void Main() {
Application.Run (new MyForm());
}
private void AddItem (string text) {
MyListView.Items.Add (text);
}
private delegate void AddItemHandler (string text);
private void AddItemFromAnotherThread (string text) {
AddItemHandler method = new AddItemHandler (AddItem);
object[] args = new object[] {text};
this.Invoke (method, args);
}
}
> whoami
The system is unable to identify you when you don't even know your name!
|
|
|
|
|
Thank you!
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
Hello,
I have made a program which searches for statements in source files. The problem which I encoutered was when loading a string from a file using ReadToEnd(), which I need to search using reg expressions. The file that I read is 6mb, but the memory used by the program increases with 30mb while I execute the line calling the method. One reason is that I'm in debug mode, but it's still too much. Also I had an earlier version of the program where I read the file line by line and it didn't use that much memory. What could be the reason for this strange behavior?
Thanks
|
|
|
|
|
The .NET Frameworks Memory Manage RESERVED that much memory for your application. It doesn't mean your actually using it.
If you want to get the real numbers, you'll have to use the Performance Monitor and the .NET Framework performance counters.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am trying to save what image has been selected to be put in a picture box, but when I use this code:
string szsavepic = pbPicture.Image.ToString();
it returns:
System.Drawing.Bitmap
Help please, it is appriciated(Spell Check?)
|
|
|
|
|
As far as I know, the Image and Bitmap objects do not store the file name.
What you can do, however, is set the tag of the Bitmap to the file name, then retrieve that tag at a later date:
string fileName = "hello.jpg";
Bitmap myBitmap = new Bitmap(fileName);
myBitmap.Tag = fileName;
pbPicture.Image = myBitmap;
Bitmap imageInPictureBox = (Bitmap)pbPicture.Image;
string theFileName = (string)myBitmap.Tag;
Further, you could put the file name and image in some dictionary/hashtable for easy use...but the above code should work fine for you with little overhead.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
How can I do this for many images?
|
|
|
|
|
For each image you load, set the .Tag of the Bitmap to the file path.
Alternatively, you could store all images in a System.Collections.Hashtable, where the key of each entry is the file path of the image, and the value of each entry is the image itself.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
I have a few buttons which have been added to a groupbox. Some of the buttons have pretty long texts (3 or 4 words) assigned them.
I've written this application on a desktop and set the size of each button so that it can well fit its text. But when I run the application on a laptop which has a smaller screen the texts on the buttons can not be fully displayed(e.g. only two and half words are visible).
I've noticed the "size" and "location" values are different for the buttons on the desktop and laptop and the font size of the buttons have also been automatically changed to smaller values when the application's running on a machine with smaller screen. But the problem is that these changes are no proportional and I think this is why that only part of the texts are displayed on the buttons.
I've tried to set the "archor" properties of the buttons to different values but the initial state of the texts are still not right. The invisible part only becomes visible after each time you change the size of the buttons at runtime. So I am wordering if there's any way to make the application to adjusts its components to the right size? At lease it should it should be able to fully display the text on a button?
|
|
|
|
|
Hi friends:
I want send parameters by reference in my .Net application. but i am using a COM+ object's method
My code is:
-----------------------------------------------------------------------
Object[] args = new Object[12];
args[0] = Agencia;
args[1] = Sector;
args[2] = Ticketera;
string[] argNames = {"cAgencia", "cSector", "cTicketera"};
res=atype.InvokeMember("b_GenerarTck",BindingFlags.InvokeMethod,null,objTicket, args,null,null,argNames);
-----------------------------------------------------------------------
BUT IT CAN'T GET THE REFERENCES
I HOPE THAT YOU CAN HELP ME
Thanks
|
|
|
|
|
What does the COM object's method signature look like? FYI, you can pass COM [in,out] parameters using the C# ref keyword. Additionally, you can pass COM [out] parameters using C# out keyword.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
this is the Signature of the method in VB 6.0 :
Public Function b_GenerarTck(ByVal cAgencia As String, _
ByVal cSector As String, _
ByVal cTicketera As String, _
ByVal cTTckBase As String, _
ByRef OUT_cTicket As Variant, _
ByRef OUT_dTicket As Variant, _
ByRef OUT_fGenerado As Variant, _
ByRef OUT_hGenerada As Variant, _
ByRef OUT_nEsperaMinima As Variant, _
ByRef OUT_dTTicket As Variant, _
ByRef OUT_dTVentanilla As Variant, _
Optional ByVal nNumCliente As Variant, _
Optional ByVal dNomCliente As Variant) As Long
The following code is the solution for a method with 1 parameter .... but doesn´t work with several parameters
--------------------------------------------------------------------
using MyMFCLibrary;
using System.Reflection;
public class MyClass
{
MyMFCAutomationServer objTest = new MyMFCAutomationServerDoc();
object [] arglist = { "Hello World!" };
ParameterModifier pm = new ParameterModifier(1);
//Set the VT_BYREF flag on the first parameter.
p[0] = true;
//Create an array of ParameterModifier objects, and then put in your element.
ParameterModifier [] pmArray = { pm };
//Use late binding and call the method.
objTest.GetType().InvokeMember("VariantByRef",
BindingFlags.InvokeMethod,
null,
objTest,
arglist,
pmArray,
null,
null);
}
------------------
Please helpme guys
=)
|
|
|
|
|
Hi,
I have two DataGrid related issues that I would like some help to resolve.
1. I need to lock the heights of all rows in my datagrid, and I have not found any way of accomplishing that. As a side note, I have found a way to lock the widths of my columns by hooking onto the ...WidthChanged event and forcing the width to its correct value for each column (is there a better way?).
So, how do I lock row heigths?
2. I have a class that derives from DataGridBoolColumn in which I want to paint icons depending on the values of the cells (true, false, null) by overloading the Paint method and do the drawing myself. I got it working, but not to my satisfaction as it involves too "much" work. What I would like to do is to use the three [True/False/Null]Value properties by assigning to each of them an instance of an Icon, and then use that instance to paint the cell with. I thought I could retrieve the Icon by using the protected method "GetColumnValueAtRow" in the Paint method, but all it returns is DBNull. If I dont alter the three ...Value properties, "GetColumnValueAtRow" returns true, false or null as its supposed to. This would be a nice solution because I don't have to figure out which Icon to paint depending on the value of the cell, since the value of the cell is infact the Icon itself. So, the only difference between my working and non-working solutions is that in the non-working one I alter the Value properties in the constructor of my derived column class. Like this:
this.TrueValue = new Icon( "true_icon.ico" );
...
I should perhaps say that I have bound a DataSet to my grid, and I add the information, which the grid is supposed to visualize, directly in my DataTable.
I can provide source code tomorrow, as the code is on my computer at work.
I hope someone can help me!
Thanks!
|
|
|
|
|
Hi!
I have a panel that contain's a richtexbox. I whant to scroll vertical bar of panel from the caret position of the contained richtextbox. Does anyone know's how.
Thanks
|
|
|
|
|
Point rtbPoint = RichTextBox.GetPositionFromCharIndex(charIndexOfCaret);
Point panelPoint = panel.PointToClient(rtbPoint);
Once you've got the panel position, you should be able to scroll to that position.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
|
i need to use C# in my desktop application to create a shortcut for my program in the startup folder using code ???? any one can help
kevin smoke
|
|
|
|
|
|
Hi all,
I am pretty new to C#. I would like to log what's going on in my application. i used log4J while programming in java. i saw some open source tools for c# but can anyone please let me know which way is better?
regards,
rnv
|
|
|
|
|
For simple logging, the System.Diagnostics namespace has the Debug and Trace classes, which you might want to look into.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
The problem with the logging block from MS that I know of is that you have to have it installed on the machine you want to run on. So if a customer has your application or a friend, they would have to have EIF installed to do the logging. With log4net you would just need to turn on the logging from the config file (or send them a config file with logging turned on).
Steve Maier, MCSD MCAD
|
|
|
|
|
Hello,
I have TextBox1 and TextBox2, and the tab index is 0 and 1 respectivelly.
Also I have a leave event on TextBox1. So the problem is, when the form containing these two controls opens, it fires the leave event on TextBox1 and sets focus to it as per tab index.
Is there a way to avoid the leave event until you actually leave the control?
Thank you
|
|
|
|
|
|
Hey! I did not get the problem. The event is fired only when it leaves the control.
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|