|
I have a treeview which lists all the chapters of a book. Whenever the treeView is selected, the program is supposed to paint the text of the entire chapter onto a tabpage.
*******************************************************************************
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
// a query is run here to produce a result of text from a certain chapter and then import it to a chap_lines string array
tabPage1.Paint += new PaintEventHandler(tabPage1_Paint);
}
private void tabPage1_Paint(object sender, PaintEventArgs e)
{
y = 8;
Graphics g = e.Graphics;
foreach (string line in chap_lines)
{
g.DrawString(line, new Font("Courier New", 10, System.Drawing.FontStyle.Regular), new SolidBrush(Color.Black), 3, y);
y = y+20;
}
}
*******************************************************************************
The problem is that the text is not painted until the next chapter node is selected. Chapter 1 is okay as it is the default node. But if I then select chapter 3, those text of chapter 1 stay there. The text of chapter 3 is not displayed until another chapter is selected.
The thing is when I debug the program setting the breakpoint at "tabPage1.Paint += new PaintEventHandler(tabPage1_Paint)", it gives me the correct result. But if I set the breakpoint anywhere in the tabPage1_Paint event, it can never get out of itself. Why is that?
How can I display its correct text once a chapter is selected?
Also, I have set the tabPage1.AutoScroll to true but it still doesn't scroll to display those lines that are not visible to the tabPage1 area.
-- modified at 22:07 Tuesday 6th June, 2006
|
|
|
|
|
Don't add the eventhandler to the paint event from the AfterSelect event. That should be done only once, preferably in the Load event. Now you are adding a new handler every time you select a chapter, which means that the tablPage1_Paint will be called multiple times whenever the control needs to be redrawn.
To cause a control to be redrawn, you use the Invalidate method of the control.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks!
But I want the user to choose what chapter they want to read. If I put the eventhandler in the Load event, it would happen only once??? Well, I think I can do it for the 1st chapter (as default page) but how about the rest of the chapters?
|
|
|
|
|
You are confusing hooking up an event with using an event.
Adding an event handler will hook up the method to the event, but it will not call the method. If you do this more than once, the event will contain more than one hook to the same method. That means that every time the event is used it will call the method more than one time.
The paint event is used automatically whenever the control needs to be redrawn. You don't use the paint event yourself. If you need the control to be redrawn you use the Invalidate method to tell the system to redraw the control.
---
b { font-weight: normal; }
|
|
|
|
|
Yes, I was confused as I'm new to C#. Anyway, I've got it working now - thanks for your help.
Could you please also advise what I can do to make the tabpage scrollable (tabPage.AutoScroll = true doesn't work and I've got missing text - those painted beyond the visible area)?
-- modified at 7:48 Wednesday 7th June, 2006
|
|
|
|
|
Are you sure that it doesn't work? Do you have any contents in it that would make it scroll?
---
b { font-weight: normal; }
|
|
|
|
|
It worked if I used labels to display text instead of painting it using graphics object. Would it be that the painting on the tabpage cannot be scrollable at all???
Someone suggested to add a label outside the visible area on the tabpage. It makes the tabpage scrollable but when I do a scroll, the painting becomes messy.
Also, it can only be scrolled down to the y location of the label. It is still a problem if the text to be displayed is beyond it.
Any suggestion for this fix?
|
|
|
|
|
The scrolling area is decided by the size needed by the child objects. The graphics you draw is no child objects, so it won't affect the scrolling area.
To get the scrolling area to be the size you need, you have to put a child object in the tabpage. Either place the child object at the position of the last line you draw, or place it at the top and resize it to the size of what you draw.
Perhaps you should make a special control to draw your text on, instead of drawing on the tappage. That would make it easier to handle scrolling also.
---
b { font-weight: normal; }
|
|
|
|
|
It works now. I have added a panel on a tabpage and have the text painted on the panel.
Thank you very much for your help.
|
|
|
|
|
How can I bind one ComboBox to another having a 2 table dataset with a relation created? I would like to view in second Combo only these records which have equal key to the record selected in the first one.
|
|
|
|
|
I'm creating a little system to interface to quickbooks inventory. I want the user to hit a button that will populate the system with the inventory items from qb. Then click a checkbox in the grid that will indicate which items that are necessary for the process.
Using the smarttags I've added a checkbox column to the grid. Then in code, after I've retrieved the xml file from qb, I add 2 more columns for the item key and description.
I noticed a little issue. If I click on any of the grid columns to reorder the grid, any checks are cleared.
Any suggestions on what I need to set for the checkboxes to maintain their values?
Thanks,
PF
|
|
|
|
|
perryf00 wrote: If I click on any of the grid columns to reorder the grid, any checks are cleared.
I checked this but didn't find such problem. Try to check your code thoroughly, specially the grid events that you used in your code and values assignment to the grid.
Best Regards.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
I have columns that I sort with column header. After clicking on column, the sort triangle icon for ascending and descending, wraps around and jumps way to the left of the column while adding a row beneath the column headers. I need the icon to stay directly to the left of the column header and not insert another row. Any ideas?
Greg
|
|
|
|
|
Perhaps you should start by mention what it is that you are doing.
Is it a windows application or a web application? Are you using some kind of component to display the columns?
---
b { font-weight: normal; }
|
|
|
|
|
|
i need help in c# that i have a code of msn messenger in c# but the problem is it need the proxy setting and and port no what i assign it and if i sign up without proxy and port no then an error of illegal mail address or password how i solve this problem any body have solution of this then help me for this thanks
|
|
|
|
|
Please use punctuation when you write. Then someone might understand what you are trying to say.
---
b { font-weight: normal; }
|
|
|
|
|
hi everybody!
how can i check if the computer is connected to the internet or not?
i don't wanna try to connect every 2 seconds or use a service for monitoring the pc...
i have to check the status changes as well.
any ideas?all welcome...
thanks in advace
Enrico
VentoEngine corp.
Program your life ^^
|
|
|
|
|
|
the problem is: i have to do something when the computer start an internet connection.
I can't simply control the status...i want to intercept the event "On Connected"..
I hope you understand
VentoEngine corp.
Program your life ^^
|
|
|
|
|
I have a class I am calling SimTreeNode which is a System.Windows.Forms.TreeNode type. I am planning on using this class within my TreeView class.
Class Definition:
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace SimTree<br />
{<br />
public class SimTreeNode : System.Windows.Forms.TreeNode<br />
{<br />
<br />
}<br />
}
As you can see, I don't do anything more or less than the TreeNode class.
The problem is, when I try to use my SimTreeNode in place of any TreeNode in my TreeView class, it throws runtime errors.
Here is the snippet of code I am doing the conversion.
using System.Collections;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Drawing;<br />
using System.Data;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Xml;<br />
using System.Xml.Serialization;<br />
using SimTree.Properties;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace SimTree<br />
{<br />
public partial class SimTree : System.Windows.Forms.TreeView<br />
{<br />
<br />
private void SimTree_ItemDrag(object sender, ItemDragEventArgs e)<br />
{<br />
Point pt = this.PointToClient(Control.MousePosition);<br />
SimTreeNode tn = (SimTreeNode)this.GetNodeAt(pt);
<br />
...<br />
}<br />
}<br />
}
Runtime Error:
Unable to cast object of type 'System.Windows.Forms.TreeNode' to type 'SimTree.SimTreeNode'.
I would like to know why I cant caste my derived type to my base type.
According to a million online forums, I don't need to make an explicit operator to caste to/from base types. I actually tried to make an explicit caste operator if you look at my comments in the SimTree.SimTreeNode class, but gave me a compiler error:
Error 1 'SimTree.SimTreeNode.explicit operator SimTree.SimTreeNode(System.Windows.Forms.TreeNode)': user-defined conversion to/from base class C:\...\SimTree\SimTreeNode.cs 10 23 SimTree
This really doesn't make any sense to me as the compiler SHOULDN'T have anyway of telling how to convert a base type to a derived type without me telling it explicitly.
I am hitting brick walls left and right with this simple thing I want to do.
|
|
|
|
|
Are you sure that all the nodes in your tree actually are SimTreeNodes? How are you adding nodes to the tree?
Melon00 wrote: I would like to know why I cant caste my derived type to my base type.
Aren't you attempting to cast from the base class (TreeNode) to the derived type (SimTreeNode)?
|
|
|
|
|
Post the code where you add nodes to the tree. Let's start there.
Josh
|
|
|
|
|
The object that you are trying to cast simply isn't a SimTreeNode. One reason could be that the GetNodeAt method didn't find any node at the point, and is returning a null value.
You have to check if the node is null before you try to cast it.
If the TreeView can contain other nodes than SimTreeNodes you should use the as keyword to cast the node. If it's not a SimTreeNode it will return null.
---
b { font-weight: normal; }
|
|
|
|
|
Just been through this myself. Life would have been so much easier if the Treeview had a free property of type Object then we could have easily added a helper class with additional properties and methods. Anyway, back to your problem. I suspect you added your SimTreeNode as a TreeNode. You can only cast in one direction. You can cast SimTreeNode stored in a Treenode variable to a SimNode, But you cannot cast a TreeNode stored in a TreeNode variable to SimNode.
You used the word converting. That's not really appropriate as the objects are not converted. All it is doing is copying pointer. We know that the derived class has all the facilities of the parent class so casting from SimtreeNode to TreeNode is safe. If the compiler let you go the other way we would end up with:
TreeNode tn = new TreeNode()
SimtreeNode stn = (SimTreeNode)tn
stn.SomeMethodThatDoesNotExistinTreeNode()
So the compiler does not allow it.
Take a look in debug just as you execute the statement and make sure that you do objects of the type you needed. Overriding ToString is always useful when you extend TreeViews.
To ensure you are safe override in SimTreeView the Add method for a treenode and make it private. Then add your own Add method for SimTreeNode
Paul
|
|
|
|