I got two Classes One is derived from TreeView and the other from TreeNode:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Resources;
using ExtendedTreeView.Properties;
namespace ExtendedTreeView
{
public partial class ExtendedTreeView : System.Windows.Forms.TreeView
{
public ExtendedTreeView()
{
InitializeComponent();
ImageList il = new ImageList();
il.Images.Add("blank", Resources.favicon);
il.Images.Add("application", Resources.application);
il.Images.Add("computer", Resources.computer);
il.Images.Add("network", Resources.network);
il.Images.Add("session", Resources.session);
il.Images.Add("user", Resources.user);
il.Images.Add("usergroup", Resources.usergroup);
this.ImageList = il;
}
}
}
and:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.NetworkInformation;
using System.Management;
using System.Windows.Forms;
using Cassia;
using System.Security.Principal;
namespace GUI
{
public class Computer : System.Windows.Forms.TreeNode, IDictionaryEnumerator
{
private DictionaryEntry nodeEntry;
private IEnumerator enumerator;
public String computerName { get; private set; }
public Computer(String computername)
{
this.computerName = computername;
enumerator = base.Nodes.GetEnumerator();
this.Text = this.ipAdressen[0].ToString() + " - " + this.computerName;
this.ImageIndex = 2;
}
#region TreeNodeStuff
public string NodeKey
{
get
{
return nodeEntry.Key.ToString();
}
set
{
nodeEntry.Key = value;
}
}
public object NodeValue
{
get
{
return nodeEntry.Value;
}
set
{
nodeEntry.Value = value;
}
}
public DictionaryEntry Entry
{
get
{
return nodeEntry;
}
}
public bool MoveNext()
{
bool Success;
Success = enumerator.MoveNext();
return Success;
}
public object Current
{
get
{
return enumerator.Current;
}
}
public object Key
{
get
{
return nodeEntry.Key;
}
}
public object Value
{
get
{
return nodeEntry.Value;
}
}
public void Reset()
{
enumerator.Reset();
}
#endregion
}
}
But the TreeNode-Icons are stuck at Index 0. So my problem is, that im not able to set the ImageIndex-Property of the Computer TreeNode.
What am I doing wrong?
Related
Hi I'm practicing using winform MVP pattern in C#.
I made Models, Presenters and Views folders, and they has a each class.
(Models has Data.cs, Presenters has Datapresenter.cs and View have interface.cs and Form.cs)
I used 'FlowLayoutPanel'. and I made Label to make numbers. Like this.
My progress so far.
Here is Data.cs (Model)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LayoutSample.Models
{
public class Data
{
public string label { get; set; }
public string CalculateArea()
{
return label;
}
}
}
Here is DataPresenter.cs (Presenter)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using LayoutSample.Models;
using LayoutSample.Views;
namespace LayoutSample.Presenters
{
public class DataPresenter
{
IFlowLabel LabelView;
public DataPresenter(IFlowLabel view)
{
LabelView = view;
}
public void CalculateArea()
{
Data data = new Models.Data();
data.label = string.Copy(LabelView.label);
var th = new Thread(() =>
{
for (int i = 0; i < 100; i++)
{
Label label = new Label();
Panel flowLayoutPanel1 = new Panel();
label.Text = i.ToString();
flowLayoutPanel1.Controls.Add(label);
Thread.Sleep(10);
}
});
th.Start();
}
}
}
Here is interface.cs(View)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LayoutSample.Views
{
public interface IFlowLabel
{
string label { get; set; }
}
}
and this is Form.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LayoutSample.Models;
using LayoutSample.Presenters;
using LayoutSample.Views;
namespace LayoutSample
{
public partial class Form1 : Form, IFlowLabel
{
public Form1()
{
InitializeComponent();
}
string IFlowLabel.label
{
get
{
return flowLayoutPanel1.ToString();
}
set
{
if (flowLayoutPanel1.InvokeRequired)
{
flowLayoutPanel1.Invoke(new MethodInvoker(() =>
{
flowLayoutPanel1.Text = value;
}));
}
else
{
flowLayoutPanel1.Text = value;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 100; i++)
{
Label label = new Label();
label.AutoSize = false;
label.Width = 50;
label.Text = i.ToString();
flowLayoutPanel1.Controls.Add(label);
}
DataPresenter presenter = new DataPresenter(this);
presenter.CalculateArea();
}
}
}
From here, I want to make the numbers increasing.
How could I increase them at same time?
p.s
I've changed DataPresenter.cs
I've chagned public void Calculate Area() to
public void CalculateArea()
{
Data data = new Models.Data();
data.label = string.Copy(LabelView.label);
var th = new Thread(() =>
{
for ( int i = 1; i < 101; i++)
{
for (int j=1; j<101;j++)
{
Label label = new Label();
label.Text = j.ToString();
Console.WriteLine(label);
}
Thread.Sleep(1000);
}
});
th.Start();
}
I can watch the numbers increasing via console, but I can't see the change in WimForm. How can I bring the increment to WinForm??
I want to make my own DropDown (Combobox) with visual Items, which contain a Picture, a Name and a Comment. The problem is if I add an Item in the properties everything is okay, visual studio adds the code in the form designer, but the item isn't displayed.
The Item Collection Class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
namespace List_Item_Test
{
public partial class My_Item : CollectionBase
{
public Items this[int Index]
{
get
{
return (Items)List[Index];
}
}
public bool Contains(Items itemType)
{
return List.Contains(itemType);
}
public int Add(Items itemType)
{
//i think hier something is missing???
return List.Add(itemType);
}
public void Remove(Items itemType)
{
List.Remove(itemType);
}
public void Insert(int index, Items itemType)
{
List.Insert(index, itemType);
}
public int IndexOf(Items itemType)
{
return List.IndexOf(itemType);
}
}
}
The Item Container Class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace List_Item_Test
{
public partial class Item_Container : UserControl
{
public Item_Container()
{
InitializeComponent();
}
My_Item hallo = new My_Item();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public My_Item MyItemTypes
{
get { return hallo; }
set
{
Items hallo1 = new Items();
hallo1.SetBounds(0, 10 + /*hallo.Count - 1 **/ 50, Width, 50);
this.Controls.Add(hallo1);
}
}
}
}
I'm making a simple application to simulate the bankteller problem.
What I'm trying to simulate is:
You have 4 counters in a store. 1 counter is open. Customers start coming in and enter the line for the first counter.
When the fourth customer enters the line for the first counter, another counter should open. The line should be equally divided between the 2 counters.When the customer at the second counter is helped and no new customers enter the line, the counter should close. Basically 4 is too many.
I can't seem to figure it out. I know I need to use a queue. But how? Could someone give me an example in console application? Preferable C#.
Thanks in advance.
Here is what I tried so far,
register class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RegisterCounter
{
class Register
{
private int customerCount;
public Queue<Customer> Line = new Queue<Customer>();
public Register()
{
customerCount = 2;
}
public Register(int customerCount)
{
this.customerCount = customerCount;
}
public int getCustomers()
{
return customerCount;
}
}
}
Customer class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RegisterCounter
{
class Customer
{
private int checkoutTime;
public Customer()
{
checkoutTime = 3;
}
public Customer(int checkoutTime)
{
this.checkoutTime = checkoutTime;
}
public int GetCheckoutTime()
{
return checkoutTime;
}
}
}
Register manager:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RegisterCounter
{
class RegisterManager
{
public List<Register> registers = new List<Register>();
Register r1 = new Register();
Customer c1 = new Customer();
public RegisterManager()
{
registers.Add(r1);
}
public void ManageCustomers()
{
for (int i = 0; i < registers.Count; i++)
{
registers.Insert(i, new Register());
if (i / 4 <= registers..Line.Count)
{
}
}
}
}
}
I am working on an asp.net web app, and I have few classes in my app_code, but for some reason I can't use any of them in my code. I tried using the same namespace, I tried without any namespace in both files, but nothing helps.
This is my page code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinkedIn;
using LinkedIn.ServiceEntities;
namespace Authentication
{
public partial class LinkedinMoreInfo : LinkedinBasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
And my code in the class:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using LinkedIn;
namespace Authorisation
{
public class LinkedInBasePage : System.Web.UI.Page
{
private string AccessToken
{
get { return (string)Session["AccessToken"]; }
set { Session["AccessToken"] = value; }
}
private InMemoryTokenManager TokenManager
{
get
{
var tokenManager = (InMemoryTokenManager)Application["TokenManager"];
if (tokenManager == null)
{
string consumerKey = ConfigurationManager.AppSettings["LinkedInConsumerKey"];
string consumerSecret = ConfigurationManager.AppSettings["LinkedInConsumerSecret"];
if (string.IsNullOrEmpty(consumerKey) == false)
{
tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
Application["TokenManager"] = tokenManager;
}
}
return tokenManager;
}
}
protected WebOAuthAuthorization Authorization
{
get;
private set;
}
protected override void OnLoad(EventArgs e)
{
this.Authorization = new WebOAuthAuthorization(this.TokenManager, this.AccessToken);
if (!IsPostBack)
{
string accessToken = this.Authorization.CompleteAuthorize();
if (accessToken != null)
{
this.AccessToken = accessToken;
Response.Redirect(Request.Path);
}
if (AccessToken == null)
{
this.Authorization.BeginAuthorize();
}
}
base.OnLoad(e);
}
}
}
Any idea what can be the problem?
Thanks in advance
Go into the properties of the files, and change the Build Action to Compile
If your base page is name LinkedInBasePage, then you need to inherit from LinkedInBasePage instead of LinkedinBasePage
public partial class LinkedinMoreInfo : Authorisation.LinkedInBasePage {
I have a NavigationBar.cs user control.
I also have NavigationItem.cs user control.
Here's the code for both:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Uboldi.CustomUI
{
public partial class NavigationBar : UserControl
{
public NavigationBar()
{
InitializeComponent();
}
public List<NavigationItem> NavigationItems { private get; set; }
public NavigationItem SelectedItem { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Uboldi.CustomUI
{
public partial class NavigationItem : UserControl
{
public NavigationItem()
{
InitializeComponent();
}
private Image _picture = null;
public Image Picture
{
get
{
return _picture;
}
set
{
_picture = value;
ptbIcon.Image = _picture;
}
}
private string _content = null;
public string Content
{
get
{
return _content;
}
set
{
_content = value;
lblDisplayText.Text = _content;
}
}
}
}
I only want a single NavigationItem in the navigationbar to be 'selected' at any given time.
When an item is selected a different color will be given to it.
My question is, where should I program this code? In the bar, or is it something a button should do and have the bar just invoke that SetYourSelfAsSelected() method?
Thanks.
I would implement this functionality in the NavigationBar for the following reason: Some other developer could use your NavigationItems in a different context where no active items are marked or marked any different. Or one wants to overload the NavigationBar to implement another behaviour for active items.