Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

maxatlis

@maxatlis
About
Posts
9
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • When Adding A Control, what events fire? [modified]
    M maxatlis

    I hope I haven’t got the wrong end of the stick of what you’re trying to achieve. I’ve just had a quick look, and found that there’s an event available for when controls are added to a user control. Try using the ControlAdded Event. To initialize it do the following… public userControl1() { InitializeComponent(); /* Please note, the code below should really be inside InitializeComponent(); But for speed, i've added it in here. Add the line below… Note: Press Tab key after typing in += as this will auto complete the rest of the event. */ this.ControlAdded+=new ControlEventHandler(userControl1_ControlAdded); } private void userControl1_ControlAdded(object sender, ControlEventArgs e) { // execute your methods for resizing to parent control. } I hope this has helped? :) P.S. I am using the latest version of C#.Net framework 3.5 so I’m guessing that these events are also available for frameworks 1.1 and 2. Rule 1 - Don’t break what’s not broken! Rule 2 - Don’t reinvent the wheel… just give it a lick of paint! Rule 3 - Keep plenty of programmer foods to hand… Pizza, beer & crisps... including the books on "How to Crash Your System in Twenty Seconds!"

    C# graphics docker question

  • Progmatically Creating TreeNodes and Child Nodes [modified]
    M maxatlis

    Big, big thank you musefan and Ian! I’ve now got it working brilliantly. Based on the pseudo-code Ian posted (which worked great after tweeking!) I’ve decided to post the working code incase anyone else out there is experiencing TreeNode’s from hell lol. "ps, i'm not great with codeproject, so if you know of a better place for me to post this answer, please let me know." Well here’s the working code… :-D :thumbsup: Add a TreeView control to Form1 and name it treeView1. and then add this code.. private void Form1_Load(object sender, EventArgs e) { TreeNode tn = new TreeNode("Root"); // set PathSeparator to url paths treeView1.PathSeparator = "/"; // Create any old folders and process InsertURL(tn, @"mywebsite.com/home/about_us.aspx"); InsertURL(tn, @"mywebsite.com/home/contact_us.aspx"); InsertURL(tn, @"mywebsite.com/home/main.aspx"); InsertURL(tn, @"mywebsite.com/blogs/seo.aspx"); InsertURL(tn, @"mywebsite.com/blogs/linkchecks.aspx"); InsertURL(tn, @"mywebsite.com/blogs/howto/gettheresults.aspx"); //add nodes to treeView treeView1.Nodes.Add(tn); } private void InsertURL(TreeNode root, string url) { InsertURL(root, SplitNodes(url), 0); } private string[] SplitNodes(string nodeString) { char[] delimiter = treeView1.PathSeparator.ToCharArray(); return nodeString.Split(delimiter, StringSplitOptions.RemoveEmptyEntries); } private void InsertURL(TreeNode parent, string[] urlParts, int index) { // Create the node if it doesn't exist. CreateNode(parent, urlParts[index]); // get the next urlPart index++; if (index < urlParts.Length) { InsertURL(parent.Nodes[urlParts[index-1]], urlParts, index); } } private static void CreateNode(TreeNode treeNode, string name) { // Add the node if it don't exist if (treeNode.Nodes[name] == null) { treeNode.Nodes.Add(name, name); } }

    modified on Saturday, March 28, 2009 5:57 AM

    C# help com data-structures question

  • Progmatically Creating TreeNodes and Child Nodes [modified]
    M maxatlis

    Don’t worry about the syntax Ian. Your pseudo-code’s pretty clear and straight forward. I’m just coding the methods out now. Fingers cross this might be the one! :-D I don’t know if anyone else has had this problem? I think I’d better post it up once we’ve got it working. Thanks so much for your help, really appreciate it :thumbsup:

    C# help com data-structures question

  • Progmatically Creating TreeNodes and Child Nodes [modified]
    M maxatlis

    lol My heads gone! I can't believe I've been beaten by the humble TreeView! And yet my web crawler is a hell of a lot more complex than that... I guess i'll take the walk of shame!! lol :laugh: i'll look at it again later Cheers again:thumbsup:

    C# help com data-structures question

  • Progmatically Creating TreeNodes and Child Nodes [modified]
    M maxatlis

    Sorry mate, just noticed that! :wtf: I've corrected temp2 as your right, it shouldn't be a new instance. I've re-tested the code but for some reason it's still populating the root nodes only??? I think i'll give it a rest for a bit and take another look later (with a fresh head); cos the code i'm looking at, to me should work. :~ :) void CreateNodes(string[] urls) { foreach (string url in urls) { string[] splits = url.Split('\\'); TreeNode temp = GetNode(splits[0], treeView1.Nodes); if (temp == null) temp = treeView1.Nodes.Add(splits[0]); for (int i = 1; i < splits.Length; i++) { temp = GetNode(splits[i], temp.Nodes); if (temp == null) temp = treeView1.Nodes.Add(splits[i]); } }

    C# help com data-structures question

  • Progmatically Creating TreeNodes and Child Nodes [modified]
    M maxatlis

    Looked very promising, but the code you sent was creating each url folder as a root node. It wasn’t breaking them down into child or grandchild nodes. ps i'm using c#.net framework 3.5 here's the code you sent... I had to modify it slightly. private void Form1_Load(object sender, EventArgs e) { TreeNode tn = new TreeNode(); treeView1.Nodes.Add(tn); string[] urls = new string[2]; urls[0] = "a\\b\\c\\d"; urls[1] = "a\\b\\e\\f"; CreateNodes(urls); } void CreateNodes(string[] urls) { foreach (string url in urls) { string[] splits = url.Split('\\'); TreeNode temp = GetNode(splits[0], treeView1.Nodes); if (temp == null) temp = treeView1.Nodes.Add(splits[0]); for (int i = 1; i < splits.Length; i++) { TreeNode temp2 = GetNode(splits[i], temp.Nodes); if (temp2 == null) temp2 = treeView1.Nodes.Add(splits[i]); } } } TreeNode GetNode(string text, TreeNodeCollection nodes) { TreeNode result = null; foreach (TreeNode n in nodes) if (n.Text == text) { result = n; break; } return result; }

    C# help com data-structures question

  • Progmatically Creating TreeNodes and Child Nodes [modified]
    M maxatlis

    Thank you so much musefan, I'll give it a go!

    C# help com data-structures question

  • Progmatically Creating TreeNodes and Child Nodes [modified]
    M maxatlis

    Hi guys I’m at my wits end with TreeNodes. X| What i'm trying to do, to me is very simple. But for some reason I just can't get my head around it! :sigh: I’m currently working on a project where basically I’m splitting a Url address into a string array and creating each node and child node from the url segments (just like the Windows Explorer.) \\ this is the plan 1) step through each url string url1 = @"www.somedomain.com\home\about_us.aspx"; string url2 = @"www.somedomain.com\home\contact_us.aspx"; string url3 = @"www.somedomain.com\home\main.aspx"; 2) split the current url into sections 3) process the url sections and create new nodes and child nodes or merge nodes if needed 4) output results the final output I'm trying to get... + www.somedomain.com _+ home ___+ about_us.aspx ___+ contact_us.aspx ___+ main.aspx but in short i'm getting something like... + www.somedomain.com _+ home ___+ about_us.aspx ___+ contact_us.aspx ___+ main.aspx _+ home ___+ about_us.aspx ___+ contact_us.aspx ___+ main.aspx Looking at the code below, Is there another way around this problem or am I just being stupid??? Any help would be very much appreciated. Please feel free to rip the hell out of my coding as I've kind of lost the plot! Thanks again! :)

    private void Form1_Load(object sender, EventArgs e)
    {
    TreeNode treeNode = new TreeNode();
    treeView1.Nodes.Add(treeNode);
    treeView1.PathSeparator = "\\"

    // Add first url address
    BuildNodes(treeNode,@"1\2\3\4\5\6\7");

    // Add the next url address merging duplicate folders together...
    BuildNodes(treeNode, @"1\2\4\5\6");
    }

    private void BuildNodes(TreeNode treeNode, string address)
    {
    string[] add = SplitNodes(address);

    int max = add.Length;
    string key = String.Empty;
    
    TreeNode\[\] treeNodes = new TreeNode\[max\];
    key = add\[0\];
    
    treeNodes\[0\] = treeNode;
    treeNodes\[0\].Text = add\[0\];
    treeNodes\[0\].Name = key;
    
    for (int i = 1; i < max; i++)
    {
        key = GetKey(key, add\[i\]);
    
        treeNodes\[i\] = new TreeNode();
        treeNodes\[i\].Text = add\[i\];
        treeNodes\[i\].Name = key;
    
        TreeNode\[\] tns = treeNodes\[i - 1\].Nodes.Find(treeNodes\[i\].Name, true);
    
        // if node exists skip it else add the new node
        if (tns.Length == 0)//if
        {
                treeNodes\[i - 1\].Nodes.Add(treeNodes\[i\]);
        }
    }
    

    }

    private string GetKey(string key, string v

    C# help com data-structures question

  • Semi Transparent UserControl
    M maxatlis

    Hi Guys Is it possible to create a usercontrol with a semi-transparent background (without affecting and not relying on the parent form’s properties). I can make the backcolor of the control transparent but I have to set the transparency key in the parent form for it to work but the form also renders out a transparent background :mad:!!!. Here is the code i'm using inside the Usercontrol :-D private void DrawImageBox() { //Set Transparent Background ( Should be Semi-Transparent at 50% Opaque) SetStyle(ControlStyles.SupportsTransparentBackGround, true); base.BackColor = Color.Transparent; //Draw Image if image is set if (Picture != null) { Graphics gfx = base.CreateGraphics(); Bitmap bmp = new Bitmap(Picture); bmp.MakeTransparent( _transparentKey ); // Stretch the image to size of control Rectangle rec = Rectangle( 0, 0, base.Width, base.Height ); // Draw the image gfx.DrawImage( bmp, rec, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel); //Clean-up gfx.Dispose(); } } If anyone has any ideas for how to do this I would be really grateful! Thanks in advance! :-D

    Graphics graphics tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups