00001 using System;
00002 using System.Collections.Generic;
00003 using System.ComponentModel;
00004 using System.Drawing;
00005 using System.Data;
00006 using System.Text;
00007 using System.Windows.Forms;
00008
00012 namespace CommentControls
00013 {
00017 [System.ComponentModel.DefaultEvent("ReplyToMe")]
00018 public partial class CommentControl : UserControl
00019 {
00021 private string id;
00023 private string poster;
00025 private string title;
00027 private string text;
00029 private DateTime date;
00031 private int commentLevel;
00032
00034 private static int nestingIndentation = 15;
00035
00039 public event CommentControlEventHandler ReplyToMe;
00043 public event CommentControlEventHandler DeleteMe;
00047 public event CommentControlEventHandler EditMe;
00048
00052 public CommentControl()
00053 {
00054 InitializeComponent();
00055 }
00056
00067 public CommentControl(string id, string poster, string title, string text, DateTime date, int commentLevel)
00068 {
00069 InitializeComponent();
00070
00071 this.id = id;
00072 this.poster = poster;
00073 this.title = title;
00074 this.text = text;
00075 this.date = date;
00076 this.commentLevel = commentLevel;
00077 lblInfo.Text = title + "by " + poster;
00078 lblTime.Text = Convert.ToString(date);
00079 txtComment.Text = text;
00080 panContainer.Padding = new Padding(commentLevel * nestingIndentation, 0, 0, 0);
00081 }
00082
00083 [
00084 TypeConverter(typeof(CommentControl)),
00085 Category("Appearance"),
00086 Description("Wether the user is allowed to reply to this comment")
00087 ]
00088 public bool CanReply
00089 {
00090 get { return lnkReply.Visible; }
00091 set { lnkReply.Visible = value; }
00092 }
00093
00094 [
00095 TypeConverter(typeof(CommentControl)),
00096 Category("Appearance"),
00097 Description("Wether the user is allowed to edit and delete this comment")
00098 ]
00099 public bool CanEdit
00100 {
00101 get { return lnkEdit.Visible; }
00102 set { lnkEdit.Visible = value; lnkDelete.Visible = value; }
00103 }
00104
00105 [
00106 TypeConverter(typeof(CommentControl)),
00107 Category("Appearance"),
00108 Description("The ID of the comment")
00109 ]
00110 public string ID
00111 {
00112 get { return id; }
00113 set { id = value; }
00114 }
00115
00116 [
00117 TypeConverter(typeof(CommentControl)),
00118 Category("Appearance"),
00119 Description("The title of the comment")
00120 ]
00121 public string Title
00122 {
00123 get { return title; }
00124 set
00125 {
00126 title = value;
00127 lblInfo.Text = value + " by " + this.poster;
00128 }
00129 }
00130
00131 [
00132 TypeConverter(typeof(CommentControl)),
00133 Category("Appearance"),
00134 Description("Who created the comment")
00135 ]
00136 public string Poster
00137 {
00138 get { return poster; }
00139 set
00140 {
00141 poster = value;
00142 lblInfo.Text = this.title + " by " + value;
00143 }
00144 }
00145
00146 [
00147 TypeConverter(typeof(CommentControl)),
00148 Category("Appearance"),
00149 Description("The text of the comment")
00150 ]
00151 public string Comment
00152 {
00153 get { return text; }
00154 set {
00155 text = value;
00156 txtComment.Text = value;
00157 }
00158 }
00159
00160 [
00161 TypeConverter(typeof(CommentControl)),
00162 Category("Appearance"),
00163 Description("When was the comment created?")
00164 ]
00165 public DateTime Date
00166 {
00167 get { return date; }
00168 set
00169 {
00170 date = value;
00171 lblTime.Text = Convert.ToString(value);
00172 }
00173 }
00174
00175 [
00176 TypeConverter(typeof(CommentControl)),
00177 Category("Appearance"),
00178 Description("How deeply is the comment nested?")
00179 ]
00180 public int CommentLevel
00181 {
00182 get { return commentLevel; }
00183 set
00184 {
00185 commentLevel = value;
00186 panContainer.Padding = new Padding(value * nestingIndentation, 0, 0, 0);
00187 }
00188 }
00189
00195 private void lnkReply_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
00196 {
00197 CommentControlEventArgs args = new CommentControlEventArgs(CommentControlEventArgs.CommentControlEventType.Reply);
00198 if (ReplyToMe != null)
00199 ReplyToMe(this, args);
00200 }
00201
00207 private void lnkDelete_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
00208 {
00209 CommentControlEventArgs args = new CommentControlEventArgs(CommentControlEventArgs.CommentControlEventType.Delete);
00210 if (DeleteMe != null)
00211 DeleteMe(this, args);
00212 }
00213
00219 private void lnkEdit_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
00220 {
00221 CommentControlEventArgs args = new CommentControlEventArgs(CommentControlEventArgs.CommentControlEventType.Edit);
00222 if (EditMe != null)
00223 EditMe(this, args);
00224 }
00225 }
00226
00230 public class CommentControlEventArgs : EventArgs
00231 {
00235 public enum CommentControlEventType
00236 {
00237 Reply,
00238 Edit,
00239 Delete
00240 }
00241
00242 private CommentControlEventType eventType;
00243
00244 public CommentControlEventType EventType
00245 {
00246 get { return eventType; }
00247 set { eventType = value; }
00248 }
00249
00254 public CommentControlEventArgs(CommentControlEventType et)
00255 {
00256 eventType = et;
00257 }
00258 }
00259
00265 public delegate void CommentControlEventHandler(
00266 object sender, CommentControlEventArgs e);
00267 }