|
Got it.
Mazy
No sig. available now.
|
|
|
|
|
I had already tried that by using image offsets generated within the events I posted above.
Although it worked, the overhead was massive when painting dynamically (i.e. as the mouse moves), it worked acceptably if I just repainted on mouse up but it wasnt the exact functionality I was after.
One other method I came up with was using bitblt functions, using this system the overhead was reduced but not drastically, for the purposes of education and future forums searchers I will post the code up tomorrow.
I will attempt to use Heath's (post below) suggestion tomorrow, as it seems like a reasonable way of doing things.
post.mode = signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
You have to P/Invoke SendMessage and send the appropriate scroll messages to the control:
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg,
int wParam, IntPtr lParam);
private const int WM_HSCROLL = 0x0114;
private const int WM_VSCROLL = 0x0115;
private const int SB_LINEDOWN = 1;
SendMessage(myControl.Handle, WM_VSCROLL, SB_LINEDOWN, IntPtr.Zero); myControl.Handle , of cousre, is the Window Handler of the control that you want to scroll, the owner of the scroll bar itself. See the documentation for WM_VSCROLL[^] and WM_HSCROLL[^] for more information.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
That is great, its exactly what I was looking for, thanks lot for the code.
One question though: I implemented the follow code snippet :
private const int WM_HSCROLL = 0x0114;
private const int WM_VSCROLL = 0x0115;
private const int SB_LINEMOVE = 1;
and thend called this within the event I posted above
SendMessage(this.Handle, WM_VSCROLL, SB_LINEMOVE, IntPtr.Zero);
SendMessage(this.Handle, WM_HSCROLL, SB_LINEMOVE, IntPtr.Zero);
The problem is that, although this will happily scroll right/down, it will not scroll up/left. After some reading of the MSDN links you posted I have been unable to locate the necessary codes to do this. Could you possibly point me in the right direction.
EDIT : After some more searching I found the following example, which set SB_LINEUP / SB_LINELEFT to 0 - interestingly this causes the my aplication to crash.
http://www.vbdesign.net/expresso/archive/topic/2739.html
post.mode = signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
The definitions for the various SB_* messages are in the winuser.h file as I mentioned in a comment in the first code example I posted. You can find these in the Platform SDK, which - if you installed the default options when installing VS.NET - is in the VS.NET installation directory, the Vc7\PlatformSDK\include. There's a whole slew of them, and they have defined them in such a way that up/left is the same numeric value, as well as down/right. Both SB_THUMBPOSITION and SB_THUMBTRACK messages are sent as notification messages you can handle in an override of WndProc to scroll your control how you see fit.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have a Windows Form with an empty ListView control set to Details view.
I create this dialog and attempt to add the columns from the DataSet to the ListView, but I'm having a problem.
//lets fill the results box
for(int x=0;x
|
|
|
|
|
Either use a positive width, or -1 to set the column width to the size necessary for the header text. -2 will set the width of only the last column to the remaining size. Doing this sequentially (since each row is the last column with each iteration) might lead to such odd behavior.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
MSDN says -2 will set the width to the header text, its even used in the example...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewcolumnheadercollectionclassaddtopic2.asp
|
|
|
|
|
What I read - also in MSDN but regarding the List-View common control which ListView encapsulates - described what I said before. A slight discrepency somewhere, but it really matters not.
The following code worked fine for me (both the commented source, and the uncommented):
using System;
using System.Drawing;
using System.Windows.Forms;
public class Test : Form
{
public static void Main()
{
Application.Run(new Test());
}
public Test()
{
ListView lv = new ListView();
Controls.Add(lv);
lv.Dock = DockStyle.Fill;
lv.View = View.Details;
foreach (string s in new string[] {"Code", "Project", "Is", "Awesome"})
{
lv.Columns.Add(s, -2, HorizontalAlignment.Left);
}
}
} I didn't catch before that you were using DataColumn.ToString . There's the problem. If you look at the documentation for DataColumn.ToString (which it overrides, but be careful because classes that don't override it and inherit from Object.ToString will return their Type as string), you'll see that it returns DataColumn.Expression , which is used to filter and calculate values. Instead, use DataColumn.Caption . If the Caption is not set, the ColumnName is returned. If you prefer, you can set the Caption when creating a strongly-typed DataSet , or you can use the database column name or an ALIAS.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Very strange....I tried the following code and got the same results, a blank ListView:
for(int x=0;x<<dSet.Tables["Documents"].Columns.Count;x++)<br />
{<br />
ColumnHeader head = new ColumnHeader();<br />
head.Text=DateTime.Now.ToString();<br />
head.Width=-2;<br />
head.TextAlign=HorizontalAlignment.Center;<br />
lvResults.Columns.Add(head);<br />
}
but if I change the -2 to 80, the ListView looks normal....I don't understand...
(I used << intentionally because the single < was interpreted as HTML and chopping off my for statement)
|
|
|
|
|
For a <, use <
First, why not just set head.Text to dsSet.Tables["Documents"].Columns[x].Caption like I mentioned before? Read the documentation for ColumnHeader.Caption and you'll see why.
As far as this not working, you have set ListView.View to View.Details , right? ListView.HeaderStyle should also be set to something other than ColumnHeaderStyle.None .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I did try using ColumnHeader.Caption with same results, so I decided to use some other string (DateTime.Now.ToString() in this case) to see if it had anything to do with using ColumnHeader text as source. The problem is not the Text, I get the correct Text when I use ColumnHeader[x].ToString(), just the width of the columns are Zero unless i set the width to a positive value. Obviously this is not criticle, but I'd like to have the columns sized to their header, and now its kinda a mission to figure out why it doesn't work.
The following are the settings for the list view:
this.lvResults.AllowColumnReorder = true;
this.lvResults.ContextMenu = this.cmResults;
this.lvResults.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvResults.FullRowSelect = true;
this.lvResults.GridLines = true;
this.lvResults.Location = new System.Drawing.Point(0, 0);
this.lvResults.MultiSelect = false;
this.lvResults.Name = "lvResults";
this.lvResults.Size = new System.Drawing.Size(536, 342);
this.lvResults.TabIndex = 0;
this.lvResults.View = System.Windows.Forms.View.Details;
this.lvResults.SelectedIndexChanged += new System.EventHandler(this.lvResults_SelectedIndexChanged);
And the HeaderStyle is set to Clickable.....
|
|
|
|
|
Hmm, this is strange. What happens when you compile and run that code fragment I posted earlier in this thread? What version of the Framework are you using? I'm just not seeing anything wrong with your code now that you've posted about everything pertinent.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I'm using v1.1 for .NET
version 2003 of VS.NET
I get same result when I compile your code.
either I need to reinstall .NET or I'm missing something.
|
|
|
|
|
I just compiled it for .NET 1.1 and my code works fine. You could try reinstalling .NET but remember that this control and many others encapsulate their Windows Common Control equivalents. Make sure you have all the latest services packs and updates first. I've followed the calls and .NET doesn't really care too much about the value of ColumnHeader.Width - it passes it to the header control for the List-View common control using SendMessage - practically unscaithed.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I've comiled your code and ran in on three machines 2 WinXP and 1 WinServer 2003, all with up2date service packs and none of them worked.....I just don't get it. Text is present, width is just zero....WTF is right.
|
|
|
|
|
I'm a pretty new programmer. I'm using C#. I'm writing a program that reads and writes data to and from an MS Access database. I have the database set up so I cannot write null values to it. When I try to do so I get an error message. I understand that the database cannot accept null values but I want the user to be able to understand this as well, I want to write a custom error message. Can someone tell me how this is done or tell me where to look for more info on this topic.
thanks
|
|
|
|
|
Create a custom form that dispalys the message. In the catch block (if you are using try-catch) just show the form!
|
|
|
|
|
Or,put all the code for database in try/catch and get OleDbException ,and check the Message or ErrorCode property and if it is that error,show an user friendly in MessageBox .
Mazy
No sig. available now.
|
|
|
|
|
a user friendly
/\ |_ E X E GG
|
|
|
|
|
Please read on and help me!
When you create a custom component and inherit (standard) from System.Windows.forms.Usercontrol, VS.NET shows a nice workarea in Design where you can place all kinds of winform controls like a textbox, button, etc.
But when I try to inherit from Panel, the area in Design disappears and is replaced by screen which says "to add components to your class.... click here to switch to code view"
I can't use this to make custom panels!
What I'm trying to do is the following:
I want a winform app (like Outlook) and everytime the user chooses a menuitem,I want to load the corresponding panel. I don't want to load all the panels at once, this will take to much time and memory.
So that's why I want to inherit from Panel, add the needed controls and then load the panel at runtime when needed.
Please, if you can help, mail me!
Or if you think I should tackle this another way, tell me so!
Thanks!
Ernst Wolthaus
|
|
|
|
|
When you inherit from Panel,if you want to add controls just double click on a controls on toolbox and they added to your form,then you should manully set the positions , size and other properties in code-behind. Whats your problem with it?
Mazy
No sig. available now.
|
|
|
|
|
When you inherit from Panel, you lose the design view in VS.NET. That was my problem.
And when I lose the design view, I can't just add controls visually because it just doesn't work right anymore.
But fortunately Jose gave me the solution, by added some attributes to the custom control.
Thanks anyway!
|
|
|
|
|
If you can't use the designer, just code the controls manually.
As far as displaying custom panels (or any scrollable control, for that matter), derive your custom panel Types (classes) and store the Type of the derivative panels as properties of the item on which the action occurs, such as clicking on a menu item. Since you're dealing with MenuItem s, also extend MenuItem with your own class and add a property, kind of like:
public class MyMenuItem : MenuItem
{
private Type panelType;
public MyMenuItem() : this(null, null) {}
public MyMenuItem(string text) : this(text, null) {}
public MyMenuItem(string text, Type panelType) : base(text)
{
this.panelType = panelType;
}
public Type PanelType
{
get { return this.panelType; }
set { this.panelType = value; }
}
} Treat this menus like normal, adding them to a MenuItems collection just like normal. When a user clicks on the MenuItem , you will use that Type as you'll see shortly. For brevity, assume that each MenuItem uses the same Click event handler:
private void menu_Click(object sender, EventArgs e)
{
MyMenuItem menu = sender as MyMenuItem;
if (menu != null)
{
if (menu.PanelType != null)
{
Panel p = Activator.CreateInstance(menu.PanelType) as Panel;
if (p != null)
{
p.Dock = DockStyle.Fill;
leftContainer.Controls.RemoveAt(0);
leftContainer.Controls.Add(p);
}
}
}
} This is just a very basic example but I hope you get the idea. Creating instances of unknown Types (or from a collection of Types, perhaps configured in a .config file) is fairly common. I do this A LOT in our enterprise app I designed. It goes much deeper than this, but this is the essential idea.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
You can create a new class A inheriting from Panel adding the next lines of code. After that all the classes inheriting from A will have again the design view.
<br />
[Designer(typeof(System.Windows.Forms.Design.DocumentDesigner),typeof(System.ComponentModel.Design.IRootDesigner))]<br />
public class A : System.Windows.Forms.Panel<br />
{<br />
....<br />
}<br />
...<br />
public yourpanel : A<br />
{<br />
....<br />
}<br />
|
|
|
|