Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4052396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:18:53+00:00 2026-05-20T14:18:53+00:00

Background : I have a C# Windows Forms application that contains a Windows service

  • 0

Background:

I have a C# Windows Forms application that contains a Windows service and an interface used to configure system settings as well as communicate with the service.

Desired Outcome:

I would like to build two versions of the solution – a client version with all the Windows service related code and form elements and a server version that contains everything.

The form contains a tabbed control, where one tab contains elements used to interface with the Windows service using sockets. All I’m really trying to achieve is that for a full build the tab containing service related elements is compiled, while for a conditional build the same tab is excluded.

Problem:

At this stage I’ve used #if directives around the Windows service related code. For example:

#if SERVERBUILD
     //Code relating to Windows service that I do not want to compile 
     //for a client version.
#endif

In the above example, ‘SERVERBUILD’ corresponds to a build configuration that I can select via the Configuration Manager (as opposed to the standard ‘Release’ build option).

The issue I’m having is that some of the code I’ve had to wrap this #if directive around lies in the WinForm.Designer.cs file in the region titled ‘Windows Form Designer generated code‘.

What seems to be occurring is that when I make a change to some of the form properties, this entire region of code seems to be deleted and re-generated, thereby removing the #if sections I had added.

  • Am I going about this the right way?
  • Is there a way to avoid the situation where I am losing the changes I’ve made in the WinForm.Designer.cs code?

I would really appreciate any advice from anyone with experience with conditional compilation and this sort of stuff.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:18:54+00:00Added an answer on May 20, 2026 at 2:18 pm
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
    

    Nuff said. Solve your problem by putting the code in the form constructor:

        public Form1() {
            InitializeComponent();
    #if !SERVERBUILD
            panel1.Visible = false;
    #endif
        }
    

    Note that using a panel is an easy way to make all the controls that are on it invisible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: we have an application that generates reports from HTML (that may or may
We have a MFC 8 application compiled with /CLR that contains a larger amount
I have this Windows Forms application where it sits in the notification area. Clicking
Scenario I have a Windows Forms Application. Inside the main form there is a
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.
Background I have made a Web Service in Visual Studio, and I'm trying to
Background I have an application written in native C++ over the course of several
I have an Expander placed on a window with a blue background and I
I have a button with a transparent background on a wpf window. Problem is,
Background: I have a little video playing app with a UI inspired by the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.