Separator control in .net Compact Framework - compact-framework

How to draw an horizontal line in .net Compact Framework 3.5, like the one used in the Owner Information in Windows Mobile 6.5, that separates the title and the body?

The easiest way to do something like that is to override the Paint event:
private const int HORZ_LINE = 10;
private void Form_Paint(object sender, PaintEventArgs e) {
using (Pen p = new Pen(Color.Black)) {
e.Graphics.DrawLine(p, 0, HORZ_LINE, Width, HORZ_LINE);
}
}

Related

Remove border of a tabcontrolbox in visual studio 2015 [duplicate]

How can I make a transparent tabPage? I found solutions like set both Form's BackColor and TransparencyKey to a color like Color.LimeGreen or override OnPaintBackground with a empty method but TabPage doesn't have neither TransparencyKeyproperty norOnPaintBackground` method. How can I do that?
TabControl is a native Windows component, it always draws the tab pages opaque with no built-in support for transparency. Solving this requires a little helping of out-of-the-box thinking, a tab control with transparent tab pages simply devolves to just the tabstrip being visible. All you have to do is use panels to host the controls that are now on the tab pages and make the correct one visible with the SelectedIndexChanged event.
Best to stick this in a derived class so you can still use the tab control normally at design time. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto the form, replacing the existing one.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
class TransparentTabControl : TabControl {
private List<Panel> pages = new List<Panel>();
public void MakeTransparent() {
if (TabCount == 0) throw new InvalidOperationException();
var height = GetTabRect(0).Bottom;
// Move controls to panels
for (int tab = 0; tab < TabCount; ++tab) {
var page = new Panel {
Left = this.Left, Top = this.Top + height,
Width = this.Width, Height = this.Height - height,
BackColor = Color.Transparent,
Visible = tab == this.SelectedIndex
};
for (int ix = TabPages[tab].Controls.Count - 1; ix >= 0; --ix) {
TabPages[tab].Controls[ix].Parent = page;
}
pages.Add(page);
this.Parent.Controls.Add(page);
}
this.Height = height /* + 1 */;
}
protected override void OnSelectedIndexChanged(EventArgs e) {
base.OnSelectedIndexChanged(e);
for (int tab = 0; tab < pages.Count; ++tab) {
pages[tab].Visible = tab == SelectedIndex;
}
}
protected override void Dispose(bool disposing) {
if (disposing) foreach (var page in pages) page.Dispose();
base.Dispose(disposing);
}
}
Call the MakeTransparent() method in the form's Load event handler:
private void Form1_Load(object sender, EventArgs e) {
transparentTabControl1.MakeTransparent();
}

Change the backcolor of current line of caret position [duplicate]

I have uploaded a image of what i want to achive...
So as you can see i want to highlight the line i click on [And update it on _textchanged event!
Is there any possible way of doing this in any colour... doesnt have to be yellow. I have searched alot but i cant understand how to get the starting length and end length and all of that.
It has confused me alot and i don;'t understand and would require some help.
Thanks for all help that is given in this thread. Also it is windows form. Im making a notepad app like notepad++ or some other notepad app... .NET Windows Form C# RichTextBox
You'll need to create your own control that inherits from RichTextBox and use that control on your form. Since the RichTextBox does not support owner drawing, you will have to listen for the WM_PAINT message and then do your work in there. Here is an example that works fairly well, though the line height is hard coded right now:
public class HighlightableRTB : RichTextBox
{
// You should probably find a way to calculate this, as each line could have a different height.
private int LineHeight = 15;
public HighlightableRTB()
{
HighlightColor = Color.Yellow;
}
[Category("Custom"),
Description("Specifies the highlight color.")]
public Color HighlightColor { get; set; }
protected override void OnSelectionChanged(EventArgs e)
{
base.OnSelectionChanged(e);
this.Invalidate();
}
private const int WM_PAINT = 15;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_PAINT)
{
var selectLength = this.SelectionLength;
var selectStart = this.SelectionStart;
this.Invalidate();
base.WndProc(ref m);
if (selectLength > 0) return; // Hides the highlight if the user is selecting something
using (Graphics g = Graphics.FromHwnd(this.Handle))
{
Brush b = new SolidBrush(Color.FromArgb(50, HighlightColor));
var line = this.GetLineFromCharIndex(selectStart);
var loc = this.GetPositionFromCharIndex(this.GetFirstCharIndexFromLine(line));
g.FillRectangle(b, new Rectangle(loc, new Size(this.Width, LineHeight)));
}
}
else
{
base.WndProc(ref m);
}
}
}

Trying to get HorizontalOffset, always returns 0

I am writing an app with C#/xaml for Windows8 Metro.
I have a Scrollviewer and would like to get the horizontaloffset.
I tryed it with this:
private void ScrollViewer_ViewChanged_1(object sender, ScrollViewerViewChangedEventArgs e)
{
int i = Convert.ToInt32(GetValue(ScrollViewer.HorizontalOffsetProperty));
}
but i is always 0, althrough in the debugger it shows me an offset of 221.09 and i scrolled down!
Michael
If you scrolled down - your horizontal offset wouldn't change unless you scrolled horizontally.
Perhaps your event handler isn't on the ScrollViewer itself and if that's the case - you would need to call GetValue on the SV itself, e.g.
private void ScrollViewer_ViewChanged_1(object sender, ScrollViewerViewChangedEventArgs e)
{
int i = Convert.ToInt32(myScrollViewer.GetValue(ScrollViewer.HorizontalOffsetProperty));
}
or better yet just do this:
private void ScrollViewer_ViewChanged_1(object sender, ScrollViewerViewChangedEventArgs e)
{
int i = Convert.ToInt32(myScrollViewer.HorizontalOffset);
}

Making custom widget on Gtk with Transparency

I'm using Gtk# and mono on Linux to make a program where I am creating a slider control over a timeline graph. I have it basically working, but there is one nagging problem that I can not figure out--- how to use transparency when using the Gtk.Style drawing routines such as "PaintBox" AND "PaintHLine". Because I could not figure out how to use these and still maintain transparency, I am currently using Cairo drawing routines, but this does not allow me to use the theme consistent look provided by the Style routines.
Currently, I have a custom widget class that has a Gtk.DrawingArea. I have a Cairo.ImageSurface kept in memory for the underlying Graph, and a Separate Cairo.ImageSurface for the "slider" which is supposed to be painted onto the DrawingArea to set a location in the timeline.
Problem is, I cannot for the life of me determine how to get my Gtk.Style.Paint... functions to draw on my Cairo.ImageSurface and still maintain transparency. Here is some sample code that is basically what I currently have:
private Cairo.ImageSurface graphImage;
private Cairo.ImageSurface gripImage;
private int grip_width;
private int grip_height;
public void MainClass() {
*...(initialization code here)...*
}
private override void OnExposeEvent() {
if (graphImage == null) {
graphImage = new Cairo.ImageSurface(Format.Rgba,graphDrawingArea.Allocation.Width,graphDrawingArea.Allocation.Height);
}
if (gripImage == null) {
gripImage = new Cairo.ImageSurface(Format.Rgba,grip_width,grip_height);
}
DrawGraph();
DrawGrip();
}
private override void OnResizeEvent() {
MakeGraph();
MakeGrip();
}
private void MakeGraph() {
using (Cairo.Context context = Gdk.CairoHelper(graphImage)) {
*...(use cairo drawing routines to draw the graph)...*
}
}
private void MakeGrip() {
using (Cairo.Context context = Gdk.CairoHelper(gripImage)) {
*...(use cairo drawing routines to draw the graph)...*
}
}
private void DrawGraph() {
using (Cairo.Context context = Gdk.CairoHelper(graphDrawingArea.GdkWindow)) {
*...(use cairo to "paint" the graphImage onto our drawing area at the proper location)...*
}
}

screen tinter

with the help of the stackoverflow community i have designed an app that colors the screen, and makes it look like you are wearing different color glasses.
i would also like to add the functionality of instead of coloring the whole screen, ONLY coloring the background of a document exactly like this program does:
http://www.thomson-software-solutions.com/html/screen_tinter.html
anyone have any clue how to do this in vb.net?
That's a pretty simple trick, it just replaces the system color that's used for window backgrounds. You'd change it by P/Invoking the SetSysColor() API function. Here's a sample Windows Forms app that demonstrates the technique. Start a new WF app and drop a button on the form. Then paste this code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
int oldcolor;
public Form1() {
InitializeComponent();
oldcolor = GetSysColor(COLOR_WINDOW);
this.FormClosed += new FormClosedEventHandler(Form1_FormClosed);
this.button1.Click += new EventHandler(button1_Click);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
int element = COLOR_WINDOW;
SetSysColors(1, ref element, ref oldcolor);
}
private int Color2COLORREF(Color color) {
return color.R | (color.G << 8) | (color.B << 0x10);
}
private void button1_Click(object sender, EventArgs e) {
int element = COLOR_WINDOW;
int colorref = Color2COLORREF(Color.NavajoWhite);
SetSysColors(1, ref element, ref colorref);
}
private const int COLOR_WINDOW = 5;
[DllImport("user32.dll")]
private static extern bool SetSysColors(int one, ref int element, ref int color);
[DllImport("user32.dll")]
private static extern int GetSysColor(int element);
}
}
Offtopic a bit, but you can change Word to default to "White on Blue". Blue background, white text.