Improvements to news control

This commit is contained in:
Jaex 2017-06-01 15:26:35 +03:00
parent e509adae42
commit 1676a9eda7
4 changed files with 60 additions and 23 deletions

View file

@ -34,7 +34,8 @@ private void InitializeComponent()
// tlpMain
//
this.tlpMain.AutoScroll = true;
this.tlpMain.ColumnCount = 1;
this.tlpMain.ColumnCount = 2;
this.tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tlpMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.tlpMain.Location = new System.Drawing.Point(0, 0);

View file

@ -43,6 +43,8 @@ public NewsListControl()
{
InitializeComponent();
tlpMain.CellPaint += TlpMain_CellPaint;
AddNewsItem(new NewsItem() { DateTimeUTC = DateTime.Now, Text = "ShareX released on Windows Store!" });
AddNewsItem(new NewsItem() { DateTimeUTC = DateTime.Now, Text = "ShareX 1.8.0 released." });
AddNewsItem(new NewsItem() { DateTimeUTC = DateTime.Now, Text = "We now have a Discord server!" });
@ -56,28 +58,62 @@ public NewsListControl()
AddNewsItem(new NewsItem() { DateTimeUTC = DateTime.Now, Text = "ShareX 1.0.0 released." });
}
private void TlpMain_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
Color color;
if (e.Row == 1)
{
color = Color.FromArgb(240, 255, 240);
}
else if (e.Row.IsEvenNumber())
{
color = Color.FromArgb(250, 250, 250);
}
else
{
color = Color.FromArgb(245, 245, 245);
}
using (Brush brush = new SolidBrush(color))
{
e.Graphics.FillRectangle(brush, e.CellBounds);
}
e.Graphics.DrawLine(Pens.LightGray, new Point(e.CellBounds.X, e.CellBounds.Bottom - 1), new Point(e.CellBounds.Right - 1, e.CellBounds.Bottom - 1));
}
public void AddNewsItem(NewsItem item)
{
NewsItems.Add(item);
Label lblNewsItem = new Label()
{
Anchor = AnchorStyles.Left | AnchorStyles.Right,
AutoSize = true,
Font = new Font("Arial", 10),
Margin = new Padding(0),
Padding = new Padding(5, 8, 5, 8),
Text = item.DateTimeUTC.ToLocalTime().ToShortDateString() + " - " + item.Text
};
lblNewsItem.BackColor = NewsItems.Count.IsEvenNumber() ? Color.FromArgb(250, 250, 250) : Color.FromArgb(245, 245, 245);
AddRow(lblNewsItem);
}
private void AddRow(Label label)
{
RowStyle style = new RowStyle(SizeType.AutoSize);
tlpMain.RowStyles.Add(style);
int index = tlpMain.RowCount++ - 1;
tlpMain.Controls.Add(label, 0, index);
Label lblDateTime = new Label()
{
Anchor = AnchorStyles.Left | AnchorStyles.Right,
AutoSize = true,
BackColor = Color.Transparent,
Font = new Font("Arial", 10),
Margin = new Padding(0),
Padding = new Padding(5, 8, 5, 8),
Text = item.DateTimeUTC.ToLocalTime().ToShortDateString()
};
tlpMain.Controls.Add(lblDateTime, 0, index);
Label lblText = new Label()
{
Anchor = AnchorStyles.Left | AnchorStyles.Right,
AutoSize = true,
BackColor = Color.Transparent,
Font = new Font("Arial", 10),
Margin = new Padding(0),
Padding = new Padding(5, 8, 5, 8),
Text = item.Text
};
tlpMain.Controls.Add(lblText, 1, index);
}
}
}

View file

@ -1869,10 +1869,10 @@ private void InitializeComponent()
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.Controls.Add(this.newsListControl1);
this.Controls.Add(this.flpPatreon);
this.Controls.Add(this.scMain);
this.Controls.Add(this.tsMain);
this.Controls.Add(this.newsListControl1);
this.DoubleBuffered = true;
this.Name = "MainForm";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);

View file

@ -277,7 +277,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;scMain.ZOrder" xml:space="preserve">
<value>3</value>
<value>4</value>
</data>
<data name="chFilename.Text" xml:space="preserve">
<value>Filename</value>
@ -373,7 +373,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;flpPatreon.ZOrder" xml:space="preserve">
<value>2</value>
<value>3</value>
</data>
<metadata name="ttMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>567, 17</value>
@ -469,7 +469,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;tsMain.ZOrder" xml:space="preserve">
<value>4</value>
<value>5</value>
</data>
<data name="tsddbCapture.ImageAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
@ -1741,13 +1741,13 @@
<value>Top, Bottom, Left, Right</value>
</data>
<data name="newsListControl1.Location" type="System.Drawing.Point, System.Drawing">
<value>328, 8</value>
<value>320, 8</value>
</data>
<data name="newsListControl1.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>0, 0, 0, 0</value>
</data>
<data name="newsListControl1.Size" type="System.Drawing.Size, System.Drawing">
<value>502, 392</value>
<value>504, 384</value>
</data>
<data name="newsListControl1.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
@ -1762,7 +1762,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;newsListControl1.ZOrder" xml:space="preserve">
<value>5</value>
<value>0</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>