0

I am getting this error "SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application" in a WinForms application, which has multiple forms whose static instances I am creating in a static class to ease the process of browsing through the forms. After several work-arounds, I figured out this solution but as with each previous solution, this error appears as soon as i start my app and is not letting me proceed. How can this error be avoided?

Dia Sheikh
  • 190
  • 2
  • 16
  • Duplicate of http://stackoverflow.com/questions/40490620/c-sharp-setcompatibletextrenderingdefault-must-be-called-before-the-first?answertab=active#tab-top? – wannadream May 22 '17 at 03:56
  • I am back at square one. The trick (mentioned in linked question) worked but i am now again getting previous error which was to be avoided in the first place. Kindly see its screenshot at: https://screenshot.net/ew06rbe – Dia Sheikh May 22 '17 at 04:52
  • 1
    There is a lot of reference: http://stackoverflow.com/questions/142003/cross-thread-operation-not-valid-control-accessed-from-a-thread-other-than-the – wannadream May 22 '17 at 04:56
  • @wannadream: I told you i tried many different solutions with result as some different kind of error. I tried this solution as well which you pointed out and see the resultant error here: https://screenshot.net/7413xtl – Dia Sheikh May 22 '17 at 06:04
  • I am totally flabbergasted as to what to do next or what & where i am doing wrong. Kindly help, as i am totally stuck on this problem since many many days, instead of focusing on my domain functionality... – Dia Sheikh May 22 '17 at 06:12
  • You assigned CurrentForm to Previous Form. Why you still check on form.IsInvokeRequired? The actual error is from PreviousForm. – wannadream May 22 '17 at 06:29
  • Yes, both errors arose on PreviousForm, but i need to save the reference to currently showing form before showing the next form. So now i checked the IsInvokeRequired for PreviousForm but here is the result :( https://screenshot.net/wrn2kh0 – Dia Sheikh May 22 '17 at 06:54
  • I also tried suggestions floated [in this question](http://stackoverflow.com/questions/9462592/best-practices-for-multi-form-applications-to-show-and-hide-forms) and from the one you referred but none seem to work. I used ApplicationContext class, created static instances of forms, then non-static instances but every situation leads to some new error. It is probably worth mentioning that my app was running fine till i was working in VS2012, as soon as i switched to VS2015, this problem started. – Dia Sheikh May 22 '17 at 07:47
  • I found a solution to the problem [here](http://stackoverflow.com/questions/43774272/cross-thread-issue-not-resolved-despite-the-usage-of-invoke/44110915#44110915). – Dia Sheikh May 22 '17 at 10:50

0 Answers0