How to change separator color in my IDesigner?

血红的双手。 提交于 2021-01-29 08:22:04

问题


I just created my own library with designer control,that used from System.ComponentModel.Design reference.So i got a winform designer in my application,like in vs.But i dont like that separator white color,how i can change it,because i dont found the property of separator color.I know that is possible to change the separator color like to grey color,because visual studio separator is grey... Image: First image is visual studio separator in designer, Second image is ugly white separator in my IDesignerHost designer.. i we tried to find some property of separator color in IDesigner and IDesignerHost,but i dont found..please help me..

How my library with IDesignerHost is works:

//surface is interface of my implemented designer,so i can get it as control
//to change basic properties,like backcolor,font,etc...
//but also i can get it as IDesigner and IDesignerHost
//but how to change a separator color?
DesignSurface surface = new DesignSurface();
Control view = surface.GetView(); //returns control or IDesigner/IDesignerHost
view.BackColor = Color.FromArgb(30, 30, 30);

回答1:


You can get the splitter from Controls collection of the view of the DesignSurface. The splitter will be added as soon as you have a component in the component tray. So you can use this code to change color of the splitter.

Example

You can try it using the following code. Just make sure you have added a reference to System.Design assembly and using System.Linq and System.ComponentModel.Design namespaces:

var surface = new DesignSurface();
var host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));
surface.BeginLoad(typeof(Form));
var root = (Form)host.RootComponent;
host.CreateComponent(typeof(BindingSource), "bindingSource1");
var view = (Control)surface.View;
view.Dock = DockStyle.Fill;
view.BackColor = Color.White;
var splitter = view.Controls.OfType<Splitter>().FirstOrDefault();
if (splitter != null)
    splitter.BackColor = Color.Red;
else
{
    view.ControlAdded += (obj, args) =>
    {
        if (args.Control is Splitter)
            args.Control.BackColor = Color.Red;
    };
}
this.Controls.Add(view);

And you will get a result like:



来源:https://stackoverflow.com/questions/57456032/how-to-change-separator-color-in-my-idesigner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!