|
I was looking at your code and not really understanding this part. Why are you using zeroVal when its a IntPtr instead of a StringBuilder? It gives an error in the compiler as well.
c:\test\notepad writer\Form1.cs(183): Argument '4': cannot convert from 'System.IntPtr' to 'System.Text.StringBuilder'
it is in reference to:
Thanks again.
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
That will do it. Thanks to pinvoke.net.
public static String GetWindowText(IntPtr hWnd)
{
IntPtr txtLength;
IntPtr retValue;
IntPtr zeroVal = new IntPtr(0);
retValue = SendMessage(hWnd,WM_GETTEXTLENGTH,zeroVal,zeroVal);
txtLength = retValue;
StringBuilder sb = new StringBuilder(txtLength.ToInt32() + 2);
retValue = SendMessage(hWnd, WM_GETTEXT, txtLength, sb);
return sb.ToString();
}
/\ |_ E X E GG
|
|
|
|
|
How doo you do that? Have you add Serializable attribute to your class?
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
I have a component that contain a collection of a struct.
I drag and drop this component on a form. than i chang it collection, i want when i close form at design time, my collection content save automatically with form(into form's code or resource).
I use this attribute :"[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]".
but this attribute can save only simle data type such "int" or "string" or ...
and not work for collection of a struct or class. my collection code is here :
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using System.Data ;
namespace DesignerSerializationVisibilityTest
{
// The code for this user control declares a public property of type DimensionData with a DesignerSerializationVisibility
// attribute set to DesignerSerializationVisibility.Content, indicating that the properties of the object should be serialized.
// The public, not hidden properties of the object that are set at design time will be persisted in the initialization code
// for the class object. Content persistence will not work for structs without a custom TypeConverter.
public class ContentSerializationExampleControl : System.Windows.Forms.UserControl
{
private System.ComponentModel.Container components = null;
int _x ;
public int X
{
get{return _x;}
set{_x=value;}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DimensionData Dimensions
{
get
{
return new DimensionData(this);
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public FieldClollectionClass ss
{
get
{
FieldClollectionClass dd=new FieldClollectionClass() ;
FieldColumn fc=new FieldColumn() ;
fc.DisplayName="AAAAAAAAAAA" ;
fc.FieldName="BBBBBBBBBBBBBB" ;
dd.Add(fc) ;
return dd ;
}
}
#region FiledColumnClass
public class FieldColumn
{
private string m_fieldName ;
[ReadOnly(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string FieldName
{
set
{
m_fieldName=value ;
}
get
{
return m_fieldName ;
}
}
public void SetFieldName(string f)
{
m_fieldName=f ;
}
private string m_displayName ;
public string DisplayName
{
get
{
return m_displayName ;
}
set
{
m_displayName=value ;
}
}
private DataTable m_columnDataTable ;
public DataTable ColumnDataTable
{
get
{
return m_columnDataTable ;
}
set
{
m_columnDataTable=value ;
}
}
private bool m_isKey ;
public bool IsKey
{
get
{
return m_isKey ;
}
set
{
m_isKey=value ;
}
}
private string m_childTableValue ;
//[DefaultValue("code")]
public string ChildTableValue
{
get
{
return m_childTableValue ;
}
set
{
m_childTableValue=value ;
}
}
private string m_childTableName ;
//[DefaultValue("name")]
public string ChildTableName
{
get
{
return m_childTableName ;
}
set
{
m_childTableName=value ;
}
}
private int m_width ;
public int Width
{
get
{
return m_width ;
}
set
{
m_width=value ;
}
}
private bool m_visible ;
//[DefaultValue(true)]
public bool Visible
{
get
{
return m_visible ;
}
set
{
m_visible=value ;
}
}
}
#endregion
[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
public class FieldClollectionClass : CollectionBase
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public FieldColumn this[int index]
{
get
{
return( (FieldColumn) List[index] );
}
set
{
List[index] = value;
}
}
public int Add( FieldColumn value )
{
return( List.Add( value ) );
}
public int IndexOf( FieldColumn value )
{
return( List.IndexOf( value ) );
}
public void Insert( int index, FieldColumn value )
{
List.Insert( index, value );
}
public void Remove( FieldColumn value )
{
List.Remove( value );
}
public bool Contains( FieldColumn value )
{
// If value is not of type FieldColumn, this will return false.
return( List.Contains( value ) );
}
}
public ContentSerializationExampleControl()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
}
[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
// This attribute indicates that the public properties of this object should be listed in the property grid.
public class DimensionData
{
private Control owner;
// This class reads and writes the Location and Size properties from the Control which it is initialized to.
internal DimensionData(Control owner)
{
this.owner = owner;
}
public Point Location
{
get
{
return owner.Location;
}
set
{
owner.Location = value;
}
}
public Size FormSize
{
get
{
return owner.Size;
}
set
{
owner.Size = value;
}
}
}
}
|
|
|
|
|
Brand new to C# here, so thanks for bearing with me. What I want to do is probably really easy, but I sure 'nuff can't find the answer on my own.
I have an aspx page with some C# code-behind and a simple button control. I want the click event on that button to launch a new aspx page sized to about 600 x 600. Just a popup window. I've tried Response.Redirect and Server.Transfer, but neither one of them seems to do what I need. A different form in the same project uses a hyperlink formatted as follows: javascript:var w=window.open('pforms/forgotpassword.aspx','test', 'width=350,height=200,scrollbars=no,resizable=yes'). I want to do basically the same thing as that hyperlink, but in C# as a button click event. Can't use a hyperlink on my aspx page for several reasons, but mainly because the event is also running some C# code. Help? Thanks!
Joel
|
|
|
|
|
The most important thing to realize is that ASP.NET is all server-side code (with the help of a couple javascript files to help with form validation). Popping up a window is completely client-side. The server can't tell the client to open a window or direct the browser to a new window - all it can do is generate and send content.
So, the server click event needs to use Page.RegisterClientScriptBlock or Page.RegisterStartupScript to register a fragment of javascript that will do this.
It's not that hard to do at all, but if you want more help, ask in the ASP.NET forum where this question should've been posted originally.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Awesome, dude. Thanks!
Joel
|
|
|
|
|
I am trying to find a specific record in the results of an SQL statement. Bascially, in non-technical terms, a query or filter on the result of a query (let's not get hung up on semantics). The data on that record is then going to be passed on to another query, but unless it has a bearing on the solution or you are interested, I won't go on about the specifics.
Thanks much....
ab
|
|
|
|
|
aberger56 wrote:
I won't go on about the specifics
With that it's rather vague, so here is a question: Are you using a stored procedure? More details on your situation will help those in the forums help answer your question.
- Nick Parker My Blog | My Articles
|
|
|
|
|
OK, here goes...
We are tying to implement a table-driven locate system to our application. Some forms (calling forms) will have a locate button on them. If they have the button, there will be records on table app_locates for that form.
app_Locates has 4 fields:
al_FormName, which holds the name of the calling form
al_FieldName, which holds the internal name of the field on which the locate can be done
al_ExternalFieldName, which is what the user will see
al_FileName, the table on which the field lives.
When the locate button on the calling form is clicked, the name of the calling form is passed to the LDB, which queries app_locates for the records which have al_FormName = the calling form's name. So, if we are on the orders form, we may get 3 records returned from app_Locates.
On the LDB, we create a radio button for each of the records returned from the query, in this case 3 radio buttons. The text that goes along with the button is the al_ExternameFieldName, so that the user sees "Customer" and not "ord_Cust", "Order Num" and not ord_OrdNum. Also on the LDB is a text box, an OK button, and a Cancel button.
So, the user clicks the Customer radio button, enters Smith in the text box, and we query the appropriate table for the information. This is where the question comes in...
let's say app_locates has 5 records:
al_FormName al_FieldName al_ExternalFieldName al_filename
icode ic_Cust Customer iCode
ordmaint om_Cust Customer orders
ordmaint om_Date Order Date orders
ordmaint om_Zip Zip Code cust
shipping sm_Cust Customer shipping
Being as the Calling Form is ordmaint, the middle 3 records are returned. The form shows with 3 radio buttons, with the External Field Name shown as the associated text.
In theory, when the user picks a radio button and enters some text in the text box, we have the info we need to find the appropriate record on the al_filename so that we can put the correct info on the calling form. The query would be:
"select * from " + app_locates.al_filename + " where " + app_locates.al_FieldName + " = " + ldb.textbox.text
The problem is, how do I find the correct record out of the 3 returned from the first query (against app_locates) to populate the second query.
I hope this makes some degree of sense. The end result is that we can add a locate field to a form simply by adding a record to app_locates.
Thanks for the help....
aberger
|
|
|
|
|
Hi
Well like you know, the developers most bring to the reallity the dreams of the boss. Now I'm tryin' to get insane with MapXtreme 2004, this is easy to show a map and ... nothing more I can't do. I wanna display the data table into a datagrid, but I can't. Someone here had used this software?? I try with the developers guide, but It's hard for me, I get confused with the namespace MapInfo.Data .
So any help, thanks.
----
hxxbin
|
|
|
|
|
You best shot for support like that, is the company that developed the library. Considering there are thousands of libraries, controls, and whatnot out there, it's very unlikely anyone has used the product.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
In the code below I load an image into a PictureBox using the Image.FromFile method. When I am done with that image I would like to release it so that I can delete it from the hard drive. However, even after I set the PictureBox's Image property to another image I still can not delete it. Obviously my process still has a handle to the file but I can't find a way to release that handle. I tried looking through the methods and properties of pictureBox1.Image but I did not see anything that looked useful. Any ideas?
------------------
pictureBox1.Image= Image.FromFile(MyFile);
pictureBox1.Image = Image.FromFile(AnotherFile);
System.IO.File.Delete(MyFile); //This fails becuase MyFile is "in use by another process"
|
|
|
|
|
Got it. Thanks.
------------------
pictureBox1.Image= Image.FromFile(MyFile);
pictureBox1.Image.Dispose();
pictureBox1.Image = Image.FromFile(AnotherFile);
System.IO.File.Delete(MyFile);
|
|
|
|
|
i was just about to say, Dispose the Image. When you Dispose an object, it releases any unmanaged resources it has open, including file handles.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi
I would like to catch an exception and then exit the method. There is a lot of code after the catch test and I was wanting to exit at that point rather without running through the rest of the code. Is there an 'exit' for a method? I have looked but cannot find anything.
Thanks in advance.
Stephen
|
|
|
|
|
|
I'm currently monitoring an service I wrote and notice in Task Manager the thread counts and handles are growing slowly and not releasing. I do the normal closing of connections and call the "dispose" method and set my objects = null. Am I missing something?
The application does the following.
1. Sink a rename file event using the "FileMonitor.EnableRaisingEvents".
2. Connect to a db using the ADODB.DLL and run SP and walk thru a recordset.
3. Walking thru a directory to see if certain files are present.
4. Create up to 17 processes objects and execute .cmd files (asynchronously) that runs ISQ and DTS packages.
5. Enumerate thru the process and check if the processes have exited.
These are the things I do to cleanup:
1. Close the recordset object and connect and call the “dispose” method. Also call the dispose on the db wrapper object.
2. Close all the processes and dispose them.
3. Set each class object equal to null.
When the service starts it only uses 8 threads and 148 handles, since it has ran twice the thread count is 12 and handles equal 307. Again any help is appreciated.
M.E. Guzman
|
|
|
|
|
|
I have an application for PocketPC devices running .net cf in which I need to trap the disposed event of a form. What should occur is this:
1. user click on the add button
2. they get a new form allowing them to add new information.
3. They click the add button and the add form disposes of itself after updating the data base.
4. the original form now needs to refresh the data on screen to reflect changes.
Being new to dot net I realize that I can do this easily by capturing the disposed action of the add form, but I can't quite figure out how to make it happen.
Any help is greatly appreciated.
-Andy Nortrup
|
|
|
|
|
Handling the Component.Disposed event would be pointless: the object is disposed - i.e., cleaned-up - before the event is fired.
Instead, call Form.ShowDialog on your add form. When the method returns, see if DialogResult.OK (or whatever is appropriate) was returned. At this point, the Form is still valid, so you can grab values like so:
using (AddForm form = new AddForm())
{
if (form.ShowDialog() == DialogResult.OK)
{
someTextBox.Text = form.SelectedItem;
}
} Using the using block like this makes sure that the modal form is disposed even if an exception is thrown. This is necessary for modal forms or you'll notice a decrease in performance and available memory over time.
This is the best way of creating a prompt box. If your form that needs to reflect the changes instantiates and shows the prompt form, then this is the most simple an extensible way of doing it (you can easily reuse your form).
Also, the Form.Closing and Form.Closed events - which are the proper events to use in order to refresh data - are not available in the .NET CF.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Many thanks, got it to do exactly what I needed.
-Andy
|
|
|
|
|
Is this possible? I don't want to merge Microsoft's .NET assemblies into the final build, but I don't want to have the distribution package to have all the little DLL files that the EXE depends on that I've written. In C++ you could do this--it was a linker option, I think.
Yeah, yeah, the idea is NOT to do this--I know. But what if I want to?
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
Marc Clifton wrote:
Yeah, yeah, the idea is NOT to do this--I know. But what if I want to?
There is program called assembly linker that can do that for you. Alternatively, just decompile all the files (i hope you know perl) and remove the interacting references from the source as well as duplicate entrypoints, then just recompile and you set
top secret xacc-ide 0.0.1
|
|
|
|
|
leppie wrote:
There is program called assembly linker that can do that for you.
Thanks!
leppie wrote:
Alternatively...
That sounded like a big "alternatively" task.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|