ThinkGeo MapView control background color in WindowsForms C#

I have a MapView UI control ( version 14 ) for Windows Forms project from ThinkGeo. I am unable to change the controls background ( or any other property of the control )

The MapView class is reference to WPF component hosted in WindowsForms using .NET8. The WPF support in project properties is enabled. I did not find a way how to access the control properties.

...
...
using ThinkGeo.Core;
using ThinkGeo.UI.WinForms;        
...
...

namespace MapApp
{
    public partial class Maps : Form
    {

        private MapView mapView;
        
        ...
        ... 

        public Maps()
        {
        
            InitializeComponent();
        
            this.SuspendLayout();
            this.DoubleBuffered = true;
            
            mapView = new ThinkGeo.UI.WinForms.MapView();

            mapView.Location = new System.Drawing.Point(0, 0);
            mapView.MapResizeMode = 
            ThinkGeo.Core.MapResizeMode.PreserveScaleAndCenter;
            mapView.MaximumScale = 1000000D;
            mapView.MinimumScale = 100D;
            mapView.Name = "mapView";
            mapView.RestrictExtent = null;
            mapView.RotatedAngle = 0F;
            mapView.Size = new System.Drawing.Size(100, 100);
            mapView.TabIndex = 0;
            mapView.MapTools.PanZoomBar.IsEnabled = false;
            mapView.MapTools.Logo.IsEnabled = false;
            //mapView.MapTools.MouseCoordinate.IsEnabled = true;
            //mapView.MapTools.ScaleLine.IsEnabled = true;
            mapView.Dock = DockStyle.Fill;
            mapView.MapUnit = GeographyUnit.Meter;

        }
    }

    ...
    ...

I was trying during the runtime debug and traverse the MapView object. I know I could get the Windows Window handle and traverse the objects and set some properties that way; I’m trying to avoid this as I hope there is a simpler more straight forward way.

The map has a BackgroundOverlay which has a BackgroundBrush property.

Give the following code a try:

mapView.BackgroundOverlay.BackgroundBrush = GeoBrushes.White;

The correct answer is the one from “salesthinkgeocom”.

At the time of writing this some additional consideration were necessary to take in account. The first part of the code is for ilustration of the state when it causes error (setting the MapView in constructor) and the second part is flowlessly working state, setting the MapView control in form_load() or on demand by user, for example button_click().

// ==============================================================
// Example of error causing code - SECTION START
// ============================================================== 
...
...
using ThinkGeo.Core;
using ThinkGeo.UI.WinForms;        
...
...

namespace MapApp
{
    public partial class Maps : Form
    {
        private MapView mapView;

        ...
        ... 

        public Maps()
        {
        
            InitializeComponent();
        
            this.SuspendLayout();
            this.DoubleBuffered = true;

            // Create mapView                
            mapView = new ThinkGeo.UI.WinForms.MapView();

            // Place control on the form / container
            this.tabControlMain.TabPages["tabPageMap"].Controls.Add(mapView);

            // Set control properties
            mapView.Location = new System.Drawing.Point(0, 0);
            mapView.MapResizeMode = 
            ThinkGeo.Core.MapResizeMode.PreserveScaleAndCenter;
            mapView.MaximumScale = 1000000D;
            mapView.MinimumScale = 100D;
            mapView.Name = "mapView";
            mapView.RestrictExtent = null;
            mapView.RotatedAngle = 0F;
            mapView.Size = new System.Drawing.Size(100, 100);
            mapView.TabIndex = 0;
            mapView.Dock = DockStyle.Fill;
            mapView.MapUnit = GeographyUnit.Meter;

            // Setting background ( and some other ) properties  of the mapView in container
            // -----------------------------------------------------------------------------
            // NOTE: setting the mapView control property here ( in constructor ) will fail - cause an error 
            // ==> System.NullReferenceException: 'Object reference not set to an instance of an object.'
            // ==> ThinkGeo.UI.WinForms.MapView.BackgroundOverlay.get returned null.
            // The control is designed in a way that it must be visible or active in user interface in order to set the property 
            // In addition, note the code above - it is placed in a tab control
            // mapView.BackgroundOverlay.BackgroundBrush = GeoBrushes.White;

            this.ResumeLayout(false);



        }
    }

    ...
    ...
// ==============================================================
// Example of error causing code - SECTION END
// ==============================================================






// ==============================================================
// Example of working code - SECTION START
// ==============================================================
...
...

// Form Load 
private void Maps_Load(object sender, EventArgs e)
{

    // Init and setting MapView control is best in form_load() ( or on user demand for example a button_click()... )      
    this.SuspendLayout();

    mapView = new ThinkGeo.UI.WinForms.MapView();

    // Make the "parent" container active / visible / enabled
    this.tabControlMain.TabPages["tabPageMap"].Controls.Add(mapView);
    this.tabControlMain.SelectedTab = tabPageMap;

    mapView.Location = new System.Drawing.Point(0, 0);
    mapView.MapResizeMode = ThinkGeo.Core.MapResizeMode.PreserveScaleAndCenter;
    mapView.MaximumScale = 1000000D;
    mapView.MinimumScale = 100D;
    mapView.Name = "mapView";
    mapView.RestrictExtent = null;
    mapView.RotatedAngle = 0F;
    mapView.Size = new System.Drawing.Size(100, 100);
    mapView.TabIndex = 0;
    mapView.Dock = DockStyle.Fill;
    mapView.MapUnit = GeographyUnit.Meter;

    // SUCCESS 
    mapView.BackgroundOverlay.BackgroundBrush = GeoBrushes.White;

    // You can deactivate / make invisible / disable the "parent" container after 
    // all desired MapView properties are set and reactivate when needed
    this.tabControlMain.SelectedTab = tabPageSettings;

    this.ResumeLayout(false);
    this.PerformLayout();
}

// ==============================================================
// Example of working code - SECTION END
// ==============================================================

In additon I have noticed that simmilar behavior apply to other properties, methods or events. What I mean by that is – if the MapView control is not visible / active / enabled then certain properties, methods or events are not accessible at that time / in that state of the control.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật