在C#中使用Singleton(Using Singleton in C#)
我正在尝试创建一个在整个应用程序中使用的类的实例。
我有两种形式:form1和form2,我有一个名为Singleton1的类。
我在form1中创建了一个名为obTest的Singleton1实例:
Singeton1 obTest = Singleton1.Instance;
从这里我需要从form2访问变量“obTest”。 是否有可能做到这一点? 如何在不创建新的Singleton1变量的情况下访问该变量?
提前致谢。
I'm trying to create an instance of a class to be used throughout the application.
I have two forms: form1 and form2 and I have a class called Singleton1.
I created an instance of Singleton1 in form1 called obTest:
Singeton1 obTest = Singleton1.Instance;
From here I need to access the variable "obTest" from form2. Is it possible to do this? How I can access that variable without creating a new Singleton1 variable?
Thanks in advance.
原文:https://stackoverflow.com/questions/9468709
最满意答案
我想我找到了答案 :
通过使
heading
具有position:absolute;
,我可以强迫它留在item
div
里面,防止它移动到它下面。 所以我更新的css(带有实际的class
名和制作材料)看起来像;.flight { height: 400px; position: relative; } .flight-img { background: red; background-size: cover; width: 40%; height: 400px; float: left; position: relative; /* CSS Animation Effects */ transition: width 0.5s ease; } .flight-heading { width: 60%; float: left; position: absolute; top: 50%; right: 0; transform: translateY(-50%); transition: width 0.5s ease; } /* Alternate img float *** /* Probably an easier way but this works for now */ .flight:nth-of-type(4n-1) .flight-img{ float: right; } .flight:nth-of-type(4n-3) .flight-img{ float: left; } .flight:nth-of-type(4n-1) .flight-heading{ left:0; } .flight:nth-of-type(4n-3) .flight-heading{ float: right; } /* Adding hover effects for desktop */ .flight:hover .flight-img { width: 100%; } .flight:hover .flight-heading { width: 100%; position:absolute; top:0; left:0; transform: translateY(50%); background: rgba(0,0,0,0.75); color: #fff; h2 { color: #fff; } }
而我的HTML看起来像:
<div id="flights"> <div class="flight"> <div class="flight-img"></div> <div class="flight-heading"> <h2>Shared Flights</h2> <p>The shared flight option is available for 1 to 5 people. This is our most economical flight. You will fly with other passengers that are booked that day.</p> <button>Book Now</button> </div> </div> <div class="clear"></div> </div><!-- End Flights -->
用JSFiddle来展示。 我知道动画需要工作,但我认为现在将
divs
放在一个地方很容易。I think I found the answer:
by making
heading
haveposition:absolute;
, I can have it forced to stay inside of theitem
div
, keeping it from moving below it. So my updated css (with actualclass
names and production stuff) looks like;.flight { height: 400px; position: relative; } .flight-img { background: red; background-size: cover; width: 40%; height: 400px; float: left; position: relative; /* CSS Animation Effects */ transition: width 0.5s ease; } .flight-heading { width: 60%; float: left; position: absolute; top: 50%; right: 0; transform: translateY(-50%); transition: width 0.5s ease; } /* Alternate img float *** /* Probably an easier way but this works for now */ .flight:nth-of-type(4n-1) .flight-img{ float: right; } .flight:nth-of-type(4n-3) .flight-img{ float: left; } .flight:nth-of-type(4n-1) .flight-heading{ left:0; } .flight:nth-of-type(4n-3) .flight-heading{ float: right; } /* Adding hover effects for desktop */ .flight:hover .flight-img { width: 100%; } .flight:hover .flight-heading { width: 100%; position:absolute; top:0; left:0; transform: translateY(50%); background: rgba(0,0,0,0.75); color: #fff; h2 { color: #fff; } }
while my html looks like:
<div id="flights"> <div class="flight"> <div class="flight-img"></div> <div class="flight-heading"> <h2>Shared Flights</h2> <p>The shared flight option is available for 1 to 5 people. This is our most economical flight. You will fly with other passengers that are booked that day.</p> <button>Book Now</button> </div> </div> <div class="clear"></div> </div><!-- End Flights -->
with a JSFiddle to show. I know the animation needs work, but I figure making it smooth will be easy now that the
divs
stay in one place.
相关问答
更多-
您需要在父级上使用:hover伪类,然后选择子元素。 .bg-onebyone:hover .stats-icon { opacity: 0.8; } 此外, .bg-onebyone .widget-stats .stats-icon对于您的HTML标记不正确,因为它将.stats-icon定位为.bg-onebyone ,它不存在。 输出: .bg-onebyone { width: 300px; height: 100px; transition: all 0.5s ease; ...
-
div都向上移动,因为它们与父元素的顶部对齐,并且您在一个底部添加了边距,扩展了父元素。 考虑改为: .dock div{ width:64px; height:64px; background:black; float:left; margin-top: 10px; transition: margin-top 0.5s; } .dock div:hover{ margin-top:0px; } ...即删除顶部的边距而不是在底部添加边距。 The divs are all ...
-
我想我找到了答案 : 通过使heading具有position:absolute; ,我可以强迫它留在item div里面,防止它移动到它下面。 所以我更新的css(带有实际的class名和制作材料)看起来像; .flight { height: 400px; position: relative; } .flight-img { background: red; background-size: cover; width: 40%; height: 40 ...
-
在悬停出口处转换过渡(Transform transition on hover exit)[2021-12-05]
使用"transition: all 0.35s;" 而不是"transition: transform 0.35s;" 上 a.box-item .text { display: flex; align-items: center; justify-content: center; position: absolute; top: 0; left: 0; right: 0; ... -
我会使用类似下面的解决方案: .btn-icon::after{ content: " " attr(title); text-indent: -9999px; letter-spacing: -10px; opacity: 0; transition: letter-spacing 0.3s ease-out, opacity 0.3s ease-out; } .btn-icon:hover::after{ text-indent: 0px; le ...
-
只需删除你的z-index: -1; 在#east-exit html { width: 100%; height: 100%; position: absolute; overflow: hidden; font-family: 'Roboto', sans-serif; } #east-exit { display: flex; opacity: 1; align-items: stretch; justify-content: space- ...
-
转换盘旋div css(Transition hover div css)[2021-10-26]
在#mydiv上添加转换延迟,然后将其覆盖:hover。 #mydiv{ z-index : 100; top : 50%; left : 50%; -webkit-transition:width 1s, height 1s, background-color 1s ,-webkit-transform 1s, margin-left 1s; transition:width 1s, height 1s, background-color 1s, transfor ... -
这是向该州过渡的持续时间。 因此,将0添加到悬停意味着它将是0s转换到悬停状态,然后1s转换回非悬停状态。 如果仅在原始非悬停时,则转换适用于两者。 It's the duration of the transition to that state. So adding 0 to hover means it will be a 0s transition to the hover state and then a 1s transition back to non-hover. If it's only ...
-
您应该将所有CSS(包括转换)设置为选择器的默认状态,然后仅设置opacity:1; 在悬停状态: div.bx-wrapper div.bx-controls-direction::before{ content: "\f053"; font-family: FontAwesome; font-style: normal; font-weight: normal; text-decoration: inherit; color: #000; ...
-
SharedElementExitTransition用于在将共享元素移动到被调用的Activity之前对共享元素执行某些操作。 例如,您可能希望在被调用的Activity接管之前将其抬起并将其移动到屏幕的中心。 重要的是,在调用startActivity之后执行共享元素退出转换。 因此,您必须在此时对共享元素进行更改。 基本上,你这样做: startActivity(intent, activityOptionsBundleWithTransitions); manipulateSharedElement ...