How to create a combo box(drop down list) with button controls for window form tool strip??? - forms

Like a layer control drop down in AutoCAD.
Thanks.

I solved it myself...
I create a user control which inherit the combo box class,this control works fine for me like a normal combo box.
Here is a code, that may help you to understand more about this control.
public partial class dropdown : ComboBox
{
public dropdown()
{
this.DrawMode = DrawMode.OwnerDrawVariable;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
// Make sure we're not trying to draw something that isn't there.
if (e.Index >= this.Items.Count || e.Index <= -1)
return;
// Get the item object.
object item = this.Items[e.Index];
if (item == null)
return;
// Draw the background color depending on
// if the item is selected or not.
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
// The item is selected.
// We want a blue background color.
e.Graphics.FillRectangle(new SolidBrush(Color.Moccasin), e.Bounds);
}
else
{
// The item is NOT selected.
// We want a white background color.
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
}
if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit)
{
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
}
// Draw the items...
LayerEdit le = (LayerEdit)item;
string text = le.LayerName.ToString();
SizeF stringSize = e.Graphics.MeasureString(text, this.Font);
// Draw layer visible(on/off)...
e.Graphics.DrawImage(byteArrayToImage(le.Visible), 2, 1 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 14, 14);
// Draw layer Lock...
e.Graphics.DrawImage(byteArrayToImage(le.Lock), 18, 1 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 15, 14);
// Draw layer plot...
e.Graphics.DrawImage(byteArrayToImage(le.Plot), 37, 1 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 14, 14);
// Draw layer color...
Brush brush = new SolidBrush(ColorTranslator.FromHtml(le.ColourValue));
e.Graphics.FillRectangle(brush, 55, 4 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 10, 10);
e.Graphics.DrawRectangle(Pens.Black, 55, 4 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 10, 10);
// Draw layer name...
e.Graphics.DrawString(text, this.Font, new SolidBrush(Color.Black), new PointF(68, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2));
}
//convert bytes into image...
public Image byteArrayToImage(byte[] byteArrayIn)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}

Related

How can i draw geojson maps on gridlayer use canvas?

I have already know how to draw map on leaflet tilelayer, but I'm trying to have a better efficiency, so now I practicing canvas with leaflet gridlayer,but the outcome wasn't I expected.I have no idea how to do it, hope someone can help me! Thanks!
Here's my code below:
var tiles = new L.GridLayer();
tiles.createTile = function (coords) {
var tile = L.DomUtil.create('canvas', 'leaflet-tile');
var ctx = tile.getContext('2d');
var size = this.getTileSize()
tile.width = size.x
tile.height = size.y
console.log(size.x);
// 将切片号乘以切片分辨率,默认为256pixel,得到切片左上角的绝对像素坐标
var nwPoint = coords.scaleBy(size)
// 根据绝对像素坐标,以及缩放层级,反投影得到其经纬度
var nw = map.unproject(nwPoint, coords.z)
//从该切片左上角开始画,画一个切片大小的无填充矩形
ctx.strokeRect(nwPoint.x, nwPoint.y, size.x, size.y)
ctx.fillStyle = 'black';
//x,y,z显示
ctx.fillText('x: ' + coords.x + ', y: ' + coords.y + ', zoom: ' + coords.z, 50, 60);
//经纬度坐标
if(nw.lng<121 && nw.lng>119){
ctx.fillText('lat: ' + nw.lat + ', lon: ' + nw.lng, 50, 80);
}
console.log(nw);
//线的颜色
ctx.strokeStyle = 'black';
//这是canvans的方法
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(size.x - 1, 0);
ctx.lineTo(size.x - 1, size.y - 1);
ctx.lineTo(0, size.y - 1);
ctx.closePath();
ctx.stroke();
// //
for (i in da.paths) {//svg casnvas
//console.log(da.paths[i].path);
context = da.paths[i].path;
p = new Path2D(context);
// console.log(p);
ctx.stroke(p);
ctx.fill(p);
ctx.fillStyle = 'lightpink';
}
return tile;
}
tiles.addTo(map)
Like this:
I really hope my map can fit the base map,
like this:
It is only a concept map, thank you!

Underlining with pdfnet results in different line thickness

The code that i use for underlining a selection of text. I begin calling the addUnderline() method, the other methods are helper methods.
private pdftron.SDF.Obj CreateUnderlineAppearance(pdftron.PDF.Rect bbox)
{
ElementBuilder builder = new ElementBuilder();
ElementWriter writer = new ElementWriter();
builder.PathBegin();
builder.MoveTo(bbox.x1, bbox.y1);
builder.LineTo(bbox.x2, bbox.y1);
Element line = builder.PathEnd();
//Set color attributes for the line...
line.SetPathFill(false);
line.SetPathStroke(true);
GState gs = line.GetGState();
gs.SetStrokeColorSpace(ColorSpace.CreateDeviceRGB());
gs.SetStrokeColor(new ColorPt(0, 0, 0)); // black
gs.SetLineWidth(2);
writer.Begin(m_document);
writer.WriteElement(line);
pdftron.SDF.Obj stm = writer.End();
builder.Dispose();
writer.Dispose();
// Set the bounding box
stm.PutRect("BBox", bbox.x1, bbox.y1, bbox.x2, bbox.y2);
stm.PutName("Subtype", "Form");
return stm;
}
public Annot CreateUnderlineAnnot(pdftron.PDF.Rect rect)
{
Annot underlineAnnot = Annot.Create(m_document, Annot.Type.e_Underline, rect);
underlineAnnot.SetAppearance(CreateUnderlineAppearance(rect));
return underlineAnnot;
}
public void AddUnderline()
{
if (m_document != null)
{
PDFViewCtrl.Selection selection = m_pdfViewer.GetSelection();
int pageNumber = selection.GetPageNum();
double[] quads = selection.GetQuads();
int numQuads = quads.Length / 8;
if (quads.Length % 8 == 0) //must have at least 8 points to be valid
{
Console.WriteLine("GetRectsFromQuads - numQuads: " + numQuads.ToString());
for (int i = 0; i < numQuads; i++)
{
Rect selectionRect = GetSelectionRect(ref quads, i);
//Console.WriteLine("GetRectsFromQuads - aRect: " + rectX1.ToString() + " | " + rectY1.ToString() + " | " + rectX2.ToString() + " | " + rectY2.ToString());
Annot underlineAnnot = CreateUnderlineAnnot(selectionRect);
m_pdfViewer.AddUnderlineAnnotationToPage(underlineAnnot, pageNumber);
//m_pdfViewer.Refresh(); --> to see how this algorithm works when debugging
}
m_pdfViewer.RefreshAnnotations();
}
}
}
You can see in the image if you look closely that some lines are thicker or thinner than others. Is this fixable? by the way, when i zoom in/out the problem is gone...
You need to set the following on your pdf view control:
PDFViewCtrl.SetThinLineAdjustment(true, true);
That will remove the aliasing on the lines, and mean all lines that are 1.5px are 1px, and so on. See here: https://www.pdftron.com/pdfnet/mobile/docs/WinRT/html/M_pdftron_PDF_PDFViewCtrl_SetThinLineAdjustment.htm

MenuItemLabel callback not working, never calls the callback, but the MenuItemImage works

Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Vector<MenuItem*> menuItems;
auto label = Label::createWithTTF("Space Combat", "fonts/Marker Felt.ttf", 24);
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
this->addChild(label, 1);
auto closeItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(MainMenu::menuCloseCallback, this));
closeItem->setPosition(origin.x + visibleSize.width - closeItem->getContentSize().width/2,
origin.y + closeItem->getContentSize().height/2);
menuItems.pushBack(closeItem);
auto playLabel = Label::createWithTTF("Play", "fonts/Marker Felt.ttf", 24);
playLabel->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height *2));
auto playItem = MenuItemLabel::create(playLabel, CC_CALLBACK_1(MainMenu::menuPlayCallback, this));
menuItems.pushBack(playItem);
auto menu = Menu::create();
menu->addChild(closeItem);
menu->addChild(playItem);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
auto sprite = Sprite::create("HelloWorld.png");
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(sprite, 0);
return true;
}
The above code will call my menuCloseCallback when the MenuItemImage is clicked on, but won't do the same for the MenuItemLabel.
Figured it out. I was positioning the label, but the menu item was being placed in the default location of 0,0 anchor 0,0. Once i added the label and positioned the menu item, all was well.

How to use DrawNode with RenderTexture cocos2d-x

I cannot draw a simple line or a dot with DrawNode and RenderTexture.
This is how to I implemented:
AppDelegate.cpp
auto scene = Scene::create();
auto layer = BackgroundLayer::create();
scene->addChild(layer);
// run
director->runWithScene(scene);
BackgroundLayer.cpp
bool BackgroundLayer::init()
{
if ( !LayerColor::initWithColor(Color4B::WHITE) )
{
return false;
}
auto renderTexture = RenderTexture::create(300, 200);
renderTexture->beginWithClear(0, 0, 0, 1); // black
auto drawPrimitive = DrawNode::create();
drawPrimitive->retain();
drawPrimitive->drawDot(Point(250, 250), 20, Color4F::RED);
drawPrimitive->visit();
renderTexture->end();
renderTexture->retain();
renderTexture->setPosition(this->getContentSize()/2);
this->addChild(renderTexture, 10000);
}
I tried with some complex shape with DrawNode, but the result is just a black rectangle stayed in the center of the screen.
I compile with cocos2d-x v3.6 & VS2013.
auto renderTexture = RenderTexture::create(50, 50);
renderTexture->beginWithClear(0, 0, 0, 1); // black
auto drawPrimitive = DrawNode::create();
drawPrimitive->retain();
drawPrimitive->drawDot(Point(10, 10), 2, Color4F::RED);
drawPrimitive->visit();
renderTexture->end();
renderTexture->retain();
renderTexture->setPosition(SCREENSIZE.width/2,SCREENSIZE.height/2);
this->addChild(renderTexture, 10000);
Try this it will create red dot on the texture

Unity3d stretch GUI.Box

I newby to Unity and I write a simple tic-tac-toe game for mobile devices.
I have troubles with GUI.Box. I try to make it stretch, but it does not work and text is clipped. My code:
GUIStyle lBoxStyle = new GUIStyle(GUI.skin.box);
lBoxStyle.stretchWidth = true;
lBoxStyle.stretchHeight = true;
lBoxStyle.wordWrap = true;
lBoxStyle.fontSize = 48;
lBoxStyle.normal.textColor = Color.black;
GUI.Box(new Rect((virtualWidth - mBoxWidth) / 2, (virtualHeight - mBoxHeight) / 2, mBoxWidth, mBoxHeight), mAlert, lBoxStyle);
How can I fix it?Also how I can reduce size if text is short?
First find out what is the size of the content with CalcSize. Then use that size to make the box tightly fitted around the content.
GUIStyle lBoxStyle = new GUIStyle(GUI.skin.box);
lBoxStyle.stretchWidth = true;
lBoxStyle.stretchHeight = true;
lBoxStyle.wordWrap = true;
lBoxStyle.fontSize = 48;
lBoxStyle.normal.textColor = Color.Black;
// Caculate the size of the content
Vector2 size = lBoxStyle.CalcSize(new GUIContent(mAlert));
// Padding if needed
// size += new Vector2(10, 10)
// Use the size as the size of the element
GUI.Box(new Rect((virtualWidth - size.x) / 2, (virtualHeight - size.y) / 2, size.x, size.y), mAlert, lBoxStyle);