How to move control at the correct position when Windows Forms is maximised - vb.net

I am using VB.NET and I have added buttons and text edits in a windows form.
When I press maximize button, the buttons and text edits do not cover the entire windows form.
I have checked the Docking method, but it works when I have few controls (like 2 or 3 buttons).
I will need to add around 20 button controls in the form.
How do I make sure the controls will move accordingly when the window form is maximized?
Thank you.

It's not so obvious to automatically adapt the position of your child controls when the parent control resizes in Windows Forms, but do you really want that ?
It seems like a terrible idea for usability.
If you want to achieve this though, you should use a TableLayoutPanel, set the size of the columns/rows to a certain percentage and then fill the panel with your controls. Here is some sample code:
this.label1.AutoSize = true;
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.label1.Location = new System.Drawing.Point(7, 0);
this.label1.Margin = new System.Windows.Forms.Padding(7, 0, 7, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(84, 25);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
this.label2.AutoSize = true;
this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
this.label2.Location = new System.Drawing.Point(105, 0);
this.label2.Margin = new System.Windows.Forms.Padding(7, 0, 7, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(84, 25);
this.label2.TabIndex = 1;
this.label2.Text = "label2";
this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tableLayoutPanel1.AutoSize = true;
this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.label2, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(147, 107);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(196, 25);
this.tableLayoutPanel1.TabIndex = 3;

Related

WxWidgets SetContainingWindow exception

I am fairly new to WxWidgets. I wrote an app that was working fine in WxWidgets 3.1.5 but gives the following exceptions in 3.2.1. I looked at the sample code that comes with 3.2.1 and I don't see any issue with my code.
../src/common/sizer.cpp(887): assert "CheckExpectedParentIs(w, m_containingWindow)" failed in SetContainingWindow(): Windows managed by the sizer associated with the given window must have this window as parent, otherwise they will not be repositioned correctly.
Please use the window wxNotebook#0x7f9a5d9547d0 ("notebook") with which this sizer is associated, as the parent when creating the window wxStaticText#0x7f9a5d957e40 ("SMART log for /dev/nvme0n1") managed by it.
Collecting stack trace information, please wait...../src/common/sizer.cpp(887): assert "CheckExpectedParentIs(w, m_containingWindow)" failed in SetContainingWindow(): Windows managed by the sizer associated with the given window must have this window as parent, otherwise they will not be repositioned correctly.
Please use the window wxNotebook#0x7f9a5d9547d0 ("notebook") with which this sizer is associated, as the parent when creating the window wxButton#0x7f9a5d9564e0 ("Copy to clilpboard") managed by it.
Collecting stack trace information, please wait...../src/common/sizer.cpp(887): assert "CheckExpectedParentIs(w, m_containingWindow)" failed in SetContainingWindow(): Windows managed by the sizer associated with the given window must have this window as parent, otherwise they will not be repositioned correctly.
Please use the window wxNotebook#0x7f9a5d9547d0 ("notebook") with which this sizer is associated, as the parent when creating the window wxGrid#0x7f9a5c892a00 ("grid") managed by it.
Here is my source
int
DlgDisplayLogs::insertPage(wxString caption, wxString hostname, wxArrayString strArray)
{
wxPanel* panel = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
wxButton* btnClipboard = new wxButton(panel, wxID_ANY, "Copy to clilpboard");
wxStaticText* label = new wxStaticText(panel, wxID_ANY, caption, wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
hbox->Add(label, 1, wxEXPAND | wxRIGHT | wxBOTTOM, 10);
hbox->Add(btnClipboard, 0, wxRIGHT | wxBOTTOM, 10);
wxGrid* grid;
int numEntries = strArray.GetCount();
grid = new wxGrid(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize);
if (!grid) {
return -1;
}
grid->CreateGrid(numEntries / 2, 2);
grid->EnableEditing(false);
grid->DisableCellEditControl();
grid->DisableDragGridSize();
grid->SetSelectionMode(wxGrid::wxGridSelectionModes::wxGridSelectRows);
grid->SetColLabelValue(0, "Description");
grid->SetColLabelValue(1, "Value");
grid->SetColMinimalWidth(0, 250);
grid->SetColMinimalWidth(1, 250);
grid->SetColSize(0, 250);
grid->SetColSize(1, 450);
grid->SetCellHighlightPenWidth(0);
grid->SetCellHighlightROPenWidth(0);
wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL);
// TODO hbox should be aligned to the right using wxALIGN_RIGHT
vbox->Add(hbox, 0, wxLEFT | wxRIGHT | wxBOTTOM, 5);
vbox->Add(grid, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
notebook->SetSizerAndFit(vbox);
notebook->AddPage(panel, hostname, true);
notebook->Layout();
//notebook->Refresh();
for (int row = 0, i = 0; i < numEntries; row++, i += 2) {
grid->SetCellValue(row, 0, strArray[i]);
grid->SetCellValue(row, 1, strArray[i + 1]);
}
return 0;
}
All help greatly appreciated.
notebook->SetSizerAndFit(vbox)
Replace that with
panel->SetSizer(vbox)
The explanation there is quite extensive. Child windows with a particular parent, can be added to a sizer that must be set to the same parent.
In your code you used panel as parent, but set the sizer to notebook.

TweenJS rect command "grow from center"

new to createjs here:
Created this fiddle: example. I would like the rect to grow from the center and not from the top left corner. I couldn't find any help, I don't know what to search for.
Code:
const PAGE_WIDTH = 150,
PAGE_HEIGHT = 75;
var stage = new createjs.Stage("canvas");
createjs.Ticker.setFPS(60);
createjs.Ticker.on("tick", tick);
var page = new createjs.Shape();
page.regX = PAGE_WIDTH/2;
page.regY = PAGE_HEIGHT/2;
page.x = 50;
page.y = 50;
stage.addChild(page);
var pageCommand = page.graphics
.beginFill('red')
.drawRect(0, 0, 1, 1).command;
createjs.Tween.get(pageCommand)
.to({w:PAGE_WIDTH, h: PAGE_HEIGHT}, 700, createjs.Ease.elasticOut)
function tick() {
stage.update();
}
Thanks.
The best way is to change the registration point of your graphics so it grows from the center.
Your code:
.drawRect(0, 0, 1, 1).command;
.to({w:PAGE_WIDTH, h: PAGE_HEIGHT})
Instead:
.drawRect(-1.-1, 2, 2);
.to({x:-PAGE_WIDTH/2, y:-PAGE_WIDTH/2, w:PAGE_WIDTH, h: PAGE_HEIGHT})
Fiddle: http://jsfiddle.net/1kjkqo2v/
[edit: I said 2 options initially, but the second (using regX and regY) wouldn't work well, since you have to tween that value as well as your size changes.]

highchart display goal on mouse hover

Below is my code to display highcharts, now in the chart goal is showed on mouse over. i want to display it as thin line:
options.series[1] = new Object();
options.series[1].name = "Goal Points";
options.series[1].data = Goallimit;
options.series[1].type = 'arearange';
options.series[1].lineWidth = 0;
options.series[1].linkedTo = ':previous';
options.series[1].color = '#A6E685';
options.series[1].fillOpacity = 0.3;
options.series[1].zIndex = 0;!
Here is Highchart image

Print Layout Not showing Properly after Set page settings in rdlc

I creating a report in rdlc in winforms. This is working properly. But after i add the page settings to the report viewer the print layout view not showing properly. Only black dots showing. When i comment the page settings it is working properly.
My report binding coding are below
this.reportViewer1.Width = this.Width - 15;
this.reportViewer1.Height = this.Height - 15;
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.ReportEmbeddedResource = "Report1.rdlc";
ReportDataSource rds = new ReportDataSource("DataSet1", CustomerList);
rds.Value = _deliveryNote.CustomerList;
this.reportViewer1.LocalReport.DataSources.Add(rds);
System.Drawing.Printing.PageSettings pg = new System.Drawing.Printing.PageSettings();
pg.Margins.Top = 100;
pg.Margins.Bottom = 100;
pg.Margins.Left = 100;
pg.Margins.Right = 100;
pg.Landscape = false;
System.Drawing.Printing.PaperSize size = new PaperSize();
size.RawKind = (int)PaperKind.A4;
pg.PaperSize = size;
this.reportViewer1.SetPageSettings(pg);
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
This is because you have not specified the height and width of the paper. Changing your code as follows will solve your problem:
System.Drawing.Printing.PageSettings pg = new PageSettings();
// Set margins
pg.Margins = new System.Drawing.Printing.Margins(100, 100, 100, 100);
// Set paper size
pg.PaperSize = new PaperSize("A4", 827, 1169); // 8.27 in x 11.69 in
pg.RawKind = (int)PaperKind.A4; // Before .NET Framework 4.5
// Update report and refresh
this.reportViewer1.SetPageSettings(pg);
this.reportViewer1.RefreshReport();
// Switch to print Layout (optional)
this.reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
For .NET Framework 4.5 and newer, the RawKind needs to be set as follows. Thanks for pointing out #Tyler Durden.
pg.PaperSize.RawKind = (int)PaperKind.A4;
Hope this helps someone in the future.

Flex 3 - Enable context menu for text object under a transparent PNG

Here is the situation. In my app I have an overlay layer that is composed of a transparent PNG. I have replaced the hitarea for the png with a 1x1 image using the following code:
[Bindable]
[Embed(source = "/assets/1x1image.png")]
private var onexonebitmapClass:Class;
private function loadCompleteHandler(event:Event):void
{
// Create the bitmap
var onexonebitmap:BitmapData = new onexonebitmapClass().bitmapData;
var bitmap:Bitmap;
bitmap = event.target.content as Bitmap;
bitmap.smoothing = true;
var _hitarea:Sprite = createHitArea(onexonebitmap, 1);
var rect:flash.geom.Rectangle = _box.toFlexRectangle(sprite.width, sprite.height);
var drawnBox:Sprite = new FlexSprite();
bitmap.width = rect.width;
bitmap.height = rect.height;
bitmap.x = -loader.width / 2;
bitmap.y = -loader.height / 2;
bitmap.alpha = _alpha;
_hitarea.alpha = 0;
drawnBox.x = rect.x + rect.width / 2;
drawnBox.y = rect.y + rect.height / 2;
// Add the bitmap as a child to the drawnBox
drawnBox.addChild(bitmap);
// Rotate the object.
drawnBox.rotation = _rotation;
// Add the drawnBox to the sprite
sprite.addChild(drawnBox);
// Set the hitarea to drawnBox
drawnBox.hitArea = _hitarea;
}
private function createHitArea(bitmapData:BitmapData, grainSize:uint = 1):Sprite
{
var _hitarea:Sprite = new Sprite();
_hitarea.graphics.beginFill(0x900000, 1.0);
for (var x:uint = 0; x < bitmapData.width; x += grainSize)
{
for (var y:uint = grainSize; y < bitmapData.height; y += grainSize)
{
if (x <= bitmapData.width && y <= bitmapData.height && bitmapData.getPixel(x, y) != 0)
{
_hitarea.graphics.drawRect(x, y, grainSize, grainSize);
}
}
}
_hitarea.graphics.endFill();
return _hitarea;
}
This is based off the work done here: Creating a hitarea for PNG Image with transparent (alpha) regions in Flex
Using the above code I am able to basically ignore the overlay layer for all mouse events (click, double click, move, etc.) However, I am unable to capture the right click (context menu) event for items that are beneath the overlay.
For instance I have a spell check component that checks the spelling on any textitem and like most other spell checkers if the word is incorrect or not in the dictionary underlines the word in red and if you right click on it would give you a list of suggestions in the contextmenu. This is working great when the text box is not under the overlay, but if the text box is under the overlay I get nothing back.
If anyone can give me some pointers on how to capture the right click event on a textItem that is under a transparent png that would be great.