|
Glacial ListView is using the existing List-View common control. Like I wrote previously, most of the controls - including the ListView control - are simply encapsulating the native common controls.
If you'd rather do this yourself, either look at the source for the Glacial ListView (that's why it's posted) or read the reference documentation for the List-View common control at http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listview/reflist.asp[^]. If you're not familiar with P/Invoke (calling native functions in .NET), read Consuming Unmanaged DLL Functions[^] in the .NET Framework SDK, as well as Marshaling Data with Platform Invoke[^].
Again, if you want examples look at the Glacial ListView. While he isn't started with the ListView defined in the BCL, it really doesn't matter. He's still constrained by the Control class and almost everything implemented in that control you can implement because it's all going back to native code. The owner drawing is what you're interested in (specifically the NM_CUSTOMDRAW (-12) message, which you can read about at http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listview/notifications/nm_customdraw_listview.asp[^]). All of these messages are sent through the WndProc defined by the Control class and overridden by every control in the .NET BCL to provide hooks (like to fire events or draw ornaments on controls).
Everything you need to know you can find in the article for the Glacial ListView as well as other articles on this site about owner drawing .NET Windows Forms Controls (which really is about owner drawing the common controls - just using managed code). I see no reason to duplicate those rather long articles here in the forums.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
Thank you veru much. You have given enough information. Now I can write what I require.
Thanks
Sundar
|
|
|
|
|
When Call a WebMothed, WebService transform data to WebApplication to xml. I want to save web method return data as a xml file on disk. How to do it?
|
|
|
|
|
Your .NET web service client is derived from WebClientProtocol . As such, you can override GetWebResponse , save the XML, and call base.GetWebResponse . For a good design, also define a property to turn this off and on (like Debug ) so that you can build a release library without a lot of code changes. Here's how I'd do it (assume implementation is in your proxy class - never update the class automatically or you'll most likely loose your changes):
#if DEBUG
bool debug = true;
[DefaultValue(true)]
#else
bool debug = false;
[DefaultValue(false)]
#endif
public bool Debug
{
get { return debug; }
set { debug = value; }
}
protected override void GetWebResponse(WebRequest request)
{
WebResponse response = base.GetWebResponse(request);
SaveResponse(response);
return response;
}
protected override void GetWebResponse(WebRequest request, IAsyncResult result)
{
WebResponse response = base.GetWebResponse(request, result);
SaveResponse(response);
return response;
}
void SaveResponse(WebResponse response)
{
if (!Debug) return;
using (FileStream file = new FileStream("response.xml", FileMode.Create,
FileAccess.Write, FileShare.Read))
{
int read = 0;
byte[] buffer = new byte[4096];
Stream s = response.GetResponseStream();
while ((read = s.Read(buffer, 0, buffer.Length)) > 0)
file.Write(buffer, 0, read);
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I know that smallguy78 has written an article on how to create the drag drop icon using a floating form but I would like to know why the internal functions can't be used.
Can anyone tell me why the following call to the windows API always returns zero (i.e. fails)
Here's the OnItemDrag statement:
<br />
protected override void OnItemDrag(ItemDragEventArgs e)<br />
{<br />
TreeView tv = this;<br />
Rectangle tnRect = tv.SelectedNode.Bounds;<br />
IntPtr iRet = SendMessage(hWndTV, (int)TreeViewMessages.TVM_CREATEDRAGIMAGE, 0, htiInsert.Handle);<br />
<br />
bool bRes = WinAPI.ImageList_BeginDrag(iRet, tv.ImageList.Images.Count-1,tnRect.X,tnRect.Y);<br />
bool bLast = WinAPI.ImageList_DragEnter(tv.Parent.Handle,0,0);<br />
base.OnItemDrag (e);<br />
}<br />
This are the Dll Import statements:
<br />
[DllImport("user32.dll")]<br />
public static extern IntPtr SendMessage(IntPtr hWnd, int iMsg, int wParam, IntPtr lParam); <br />
<br />
[DllImport("comctl32.dll")]<br />
public static extern bool ImageList_DragEnter(IntPtr hWnd, int x, int y);<br />
<br />
[DllImport("comctl32.dll")]<br />
public static extern bool ImageList_DragMove(int x, int y);
All 3 API calls fail! Huh?
Has this functionality been disabled? The code is there for C++ programmers but sadly ineffectual in C#. Can anyone throw any light on this?
|
|
|
|
|
Tell us the nature of the failure - i.e. what exception is thrown, the stack trace (if any), and the message - would help.
These should work. Native APIs like the 3 above can be called from C# (or any supporting managed language like VB.NET) using Platform Invoke (or P/Invoke). This requires that you have permission to call unmanaged code, however. With the default permissions granted the various zones on your machine, running code from your local machine is the only zone that will give you this permissions. This has to do with Code Access Security.
More information about your execution environment is necessary.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
i've converted a dateTime to a string using the following:
[datetime].Start.ToString("yyyyMMdd'T'HHmmss");
let's say i've saved this out to a text file and now i'm reading the information back in as a string. how would i then convert this dateTime string back to a System.DateTime object?
thanks,
Rob Tomson
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
If you use the built-in format provider with the switch 's' you get aery similar format to yours above and you can use the parse static method on a DateTime...eg:
<br />
string s = DateTime.Now.ToString("s");<br />
Console.WriteLine(s);<br />
DateTime parsedDateTime = DateTime.Parse(s);<br />
Console.WriteLine(parsedDateTime);<br />
the "S" switch is defined as this format in the Docs:
2002-01-03T00:00:00
yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)
If you really want your own format then you can write your own class which implements IFormatProvider, or inherits from DateTimeFormatInfo.
DateTimeFormatInfo[^]
|
|
|
|
|
Hi all.
I have a feeling there is a very simple solution to my problem, but I just can't figure it out. Here goes: I have a form with a treeview (and a listview with the same problem), where I present different items. I have a context menu connected to the view giving the user the option to, for instance, edit or delete the selected item. The problem is that if the user has selected an item and then right clicks on another item and choose to edit, it's the first item that 'opens' to be edited. I would want the right click to FIRST select the item that was being clicked and THEN popping up the context menu so that the user edits or deletes the item that was being right clicked.
Any tips?
Thanks
/EnkelIk
|
|
|
|
|
|
It will require you to write code to select the node when the user right-clicks. It is fairly easy to write and I believe CodeProject has some examples of this. Search the .NET Controls section. The default controls don't support the feature you want.
-
Drew
|
|
|
|
|
This is a problem with your code that can easily be solved. Right-clicking a node should NOT select it. This is counter-intuitive as it does not follow the Windows UI Guidelines that exist to present a common user interface experience. If you change the behavior your liable to confuse users who are used to the way "everything else works".
Make sure that either tie a ContextMenu to a node by referencing a particular ContextMenu (presumably, certain types of nodes all reference the same instance of a ContextMenu to save resources) by assigning an instance to the TreeNode.Tag property. Conversely, you could implement the popup of specific ContextMenu s based on data in the TreeNode (like that from the Text or Tag properties; or perhaps you extend TreeNode with your own derivative).
Leave TreeView.ContextMenu unassigned. Instead, handle the MouseUp event (or, if you're extending TreeView , override the OnMouseUp protected method for better control and faster execution; just be sure to call base.OnMouseUp ).
This gives you translated mouse coordinates (to the client, or control) that you can use in a call to TreeView.GetNodeAt :
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
Point pt = new Point(e.X, e.Y);
TreeNode node = GetNodeAt(pt);
if (node != null)
{
ContextMenu cm = node.Tag as ContextMenu;
if (cm != null)
cm.Show(this, pt);
}
} There's an example of getting the reference to the ContextMenu you want assigned to the TreeNode.Tag property. Again - reuse references to distinct ContextMenu s so you don't hot system resources and otherwise frustrate the user when you start getting lots of tree nodes or have large context menus.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I am writing an application of capturing any window in C# application(winform). My application is like u can capture any window in ur application and then use it from there. Can anybody tell me how should i do this and whether i use API or there in built class provided in C#. Thanks in advance
Regards.
|
|
|
|
|
This has been discussed in this forum before. Please click on "Search comments" above and search for something like "screen capture" or "remote screen".
C# - .NET for that matter - is not currently a suitable platform for this low-level operation. Solutions that actively take screenshots are cludgy, slow, and prone to many problems in a point-and-click interface.
The correct solution is low-level: virtual frame buffers. This redirects all GDI and GDI+ drawing to a virtual HDC that is redirected through the wire (often after being compressed).
If you do go with a screenshot approach, at least use intelligent algorithms to determine which areas of a screen have changed and only send those down the wire. Some existing solutions work this way. It's a lot better than sending down entire screenshots continuously because it requires a lot less bandwidth and transfer time and provides a much, much better user experience.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I want to send a simple string (name) to a crystal report for placing in the title of the report. I don't want to use this string in a formula, parameter, boat, or on a train...
I was able to use the code below to get it to work...
Is this the best way to go about this?
//set the Formulas collection to the current report's formula collection
FormulaFieldDefinitions crFormulas = crReport.DataDefinition.FormulaFields;
//set the formula fields in the order they appear on the report.
FormulaFieldDefinition crFormulaTextField1 = crFormulas[0];
//pass in the Field names Chr(34) is double quotes character
crFormulaTextField1.Text = '"'+name+'"';
thanks,
Ron
|
|
|
|
|
Okay, so your program is ending from some other point. You will need to put the write to log code at the point you make the determination that the application is coming to an end. If that is in multiple places then, depending on the way your application is structures, you might consider a central clean up method that you run that cleans up, writes to the log, and performs the necessary exit routines.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Thank for all the help I really appreciate it. Ok so my program ends if the X in the top right corner is clicked is there any way to catch this event??
|
|
|
|
|
Not that I know of, at least in a console application.
Could this be re-written as a Winforms application? You could have a very simple form with just a close button and that event can be caught easily.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Hi,
I've used the following code to get all the section names from an ini file. But whats happening is, am getting only one section name. But the documentation for 'GetPrivateProfileSectionNames' says that that first parameter will contain a "Pointer to a buffer that receives the section names associated with the named file. The buffer is filled with one or more null-terminated strings; the last string is followed by a second null character."
The following is the code that i've used.
//--------------------------------------------------------------------------
StringBuilder temp = new StringBuilder(8192);
int nRetValue = GetPrivateProfileSectionNames(temp, 8192, m_strIniFilePath);
string strSectionNames = temp.ToString();
string[] strArrSectionNames = strSectionNames.Split(null);
//--------------------------------------------------------------------------
Any help would be greatly appreciated.
Thanks and Regards
Vikram Attiganal
|
|
|
|
|
I would imaging that when this is converted in to C# the StringBuilder is reading to the first null and then stops because it thinks it is the end of the string. Strings in C/C++ are null terminated.
What you will need to do is to go through your buffer and find all the nulls yourself and converting it to a string by pointing to the byte after the each null terminator.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
You would be "imagining" correctly!
GetPrivateProfileSectionNames (and I assume the original poster is P/Invoking this) fills a string buffer with NULL-delimited strings, with the last string having a second NULL terminator. This is actually pretty common with Win32 APIs when using string buffers with arra-like content (like the GetOpenFileName and GetSaveFileName APIs for the file type filters).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi
I successfully worked with Remoting Concepts. What my question is, how could we popup message in that remote application. Like Yahoo & MSN Messanger displayes "You have one new mail" then it continues. Like that, My remote server running in separate IP address, if any client that called the method in remote server, then it immediately popups up message like you are called from this person <their name="" or="" ip="">, then continues with the client.
Instead of popups if invoking separate form, it works but i should show the form as ShowDialog instead of show. If it could be showdialog then the client application waits until the form closed from the server. Its a problem for me if no one respond in server place, the client application waits.
I need some sort of solution on this, Thanks in Advance. I don't know this is the right way or we have some other way to intimate to the remote server that they receive some message. I need some possible solutions.
Chandru
|
|
|
|
|
|
|
I used this code for doin the samething...
ifstream(fp);
char buf[200];
fp.open("input.txt", ios::in);
fp.getline(buf,200,'\n');
this code reads first line in the file at a time and stores it into the array buf and increments the pointer to nextline. if u want u can use a condition like fp.EOF (end of file condition) or use a any loop to read line by line...
Hope this helps....
Good Luck
Suman
|
|
|
|