Skip to content

Commit

Permalink
enabled AutoSize for Form1
Browse files Browse the repository at this point in the history
the custom logic seemed to not work nicely in
some cases (#15). also moved vertical buttons
to their own UserControl
  • Loading branch information
zumoshi committed Sep 7, 2016
1 parent cf93c03 commit b3b0f04
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 32 deletions.
9 changes: 9 additions & 0 deletions BrowserSelect/BrowserSelect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<Compile Include="BrowserUC.Designer.cs">
<DependentUpon>BrowserUC.cs</DependentUpon>
</Compile>
<Compile Include="ButtonsUC.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="ButtonsUC.Designer.cs">
<DependentUpon>ButtonsUC.cs</DependentUpon>
</Compile>
<Compile Include="ForegroundAgent.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -95,6 +101,9 @@
<EmbeddedResource Include="BrowserUC.resx">
<DependentUpon>BrowserUC.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="ButtonsUC.resx">
<DependentUpon>ButtonsUC.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
Expand Down
45 changes: 45 additions & 0 deletions BrowserSelect/ButtonsUC.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions BrowserSelect/ButtonsUC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 BrowserSelect
{
public partial class ButtonsUC : UserControl
{
public ButtonsUC()
{
InitializeComponent();
add_button("About", show_about, 0);
add_button("Settings", show_setting, 1);
}

private void show_setting(object sender, EventArgs e)
{
new frm_settings().ShowDialog();
}

private void show_about(object sender, EventArgs e)
{
new frm_About().ShowDialog();
}

private List<VButton> vbtn = new List<VButton>();
private void add_button(string text, EventHandler evt, int index)
{
// code for vertical buttons on the right, they are custom controls
// without support for form designer, so we initiate them in code
var btn = new VButton();
btn.Text = text;
btn.Anchor = AnchorStyles.Right;
btn.Width = 20;
btn.Height = 75;
btn.Top = index * 80;
//btn.Left = this.Width - 35;
//btn.Left = btn_help.Right - btn.Width;
btn.Left = 5;
Controls.Add(btn);
btn.Click += evt;

vbtn.Add(btn);
}
}
}
120 changes: 120 additions & 0 deletions BrowserSelect/ButtonsUC.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
35 changes: 3 additions & 32 deletions BrowserSelect/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ private void Form1_Load(object sender, EventArgs e)
this.Controls.Add(buc);
}
// resize the form
this.Width = i * 128 + 20 + 20;
//this.Width = i * 128 + 20 + 20;
this.AutoSize = true;
this.KeyPreview = true;
this.Text = Program.url;
// set the form icon from .exe file icon
this.Icon = IconExtractor.fromFile(Application.ExecutablePath);
// add vertical buttons to right of form
add_button("About", show_about, 0);
add_button("Settings", show_setting, 1);
this.Controls.Add(new ButtonsUC() { Left = i * 128 });

// create a wildcard rule for this domain (always button)
_alwaysRule = generate_rule(Program.url);
Expand Down Expand Up @@ -170,35 +170,6 @@ e.g. sealake.vic.au or something.fun.ir
};
}

private void show_setting(object sender, EventArgs e)
{
new frm_settings().ShowDialog();
}

private void show_about(object sender, EventArgs e)
{
new frm_About().ShowDialog();
}

private List<VButton> vbtn = new List<VButton>();
private void add_button(string text, EventHandler evt, int index)
{
// code for vertical buttons on the right, they are custom controls
// without support for form designer, so we initiate them in code
var btn = new VButton();
btn.Text = text;
btn.Anchor = AnchorStyles.Right;
btn.Width = 20;
btn.Height = 75;
btn.Top = index * 80;
//btn.Left = this.Width - 35;
btn.Left = btn_help.Right - btn.Width;
Controls.Add(btn);
btn.Click += evt;

vbtn.Add(btn);
}

private void browser_click(object sender, EventArgs e)
{
// callback for click event inside the browserControls
Expand Down

0 comments on commit b3b0f04

Please sign in to comment.